Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:25

0001 // History.h is a part of the PYTHIA event generator.
0002 // Copyright (C) 2024 Torbjorn Sjostrand.
0003 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
0004 // Please respect the MCnet Guidelines, see GUIDELINES for details.
0005 
0006 // This file is written by Stefan Prestel.
0007 // It contains the main class for matrix element merging.
0008 // Header file for the Clustering and History classes.
0009 
0010 #ifndef Pythia8_History_H
0011 #define Pythia8_History_H
0012 
0013 #include "Pythia8/Basics.h"
0014 #include "Pythia8/BeamParticle.h"
0015 #include "Pythia8/Event.h"
0016 #include "Pythia8/Info.h"
0017 #include "Pythia8/ParticleData.h"
0018 #include "Pythia8/PartonLevel.h"
0019 #include "Pythia8/PythiaStdlib.h"
0020 #include "Pythia8/Settings.h"
0021 #include "Pythia8/StandardModel.h"
0022 #include "Pythia8/SimpleWeakShowerMEs.h"
0023 
0024 namespace Pythia8 {
0025 
0026 //==========================================================================
0027 
0028 // Declaration of Clustering class.
0029 // This class holds information about one radiator, recoiler, emitted system.
0030 // This class is a container class for History class use.
0031 
0032 class Clustering {
0033 
0034 public:
0035 
0036    // The emitted parton location.
0037   int emitted;
0038   // The emittor parton
0039   int emittor;
0040   // The recoiler parton.
0041   int recoiler;
0042   // The colour connected recoiler (Can be different for ISR)
0043   int partner;
0044   // The scale associated with this clustering.
0045   double pTscale;
0046   // The flavour of the radiator prior to the emission.
0047   int flavRadBef;
0048   // Spin of the radiator (-1 is left handed, +1 is right handed).
0049   int spinRad;
0050   // Spin of the emitted  (-1 is left handed, +1 is right handed).
0051   int spinEmt;
0052   // Spin of the recoiler (-1 is left handed, +1 is right handed).
0053   int spinRec;
0054   // Spin of the radiator before the splitting.
0055   int spinRadBef;
0056   // The radiator before the splitting.
0057   int radBef;
0058   // The recoiler before the splitting.
0059   int recBef;
0060 
0061   // Map between particle positions in the clustered states -> particle
0062   // positions in unclustered real-emission state.
0063   map<int,int> iPosInMother;
0064 
0065   // Default constructor
0066   Clustering() : emitted(0), emittor(0), recoiler(0), partner(0), pTscale(),
0067     flavRadBef(0), spinRad(9), spinEmt(9), spinRec(9), spinRadBef(9),
0068     radBef(0), recBef(0), iPosInMother() {}
0069 
0070   // Default destructor
0071   ~Clustering(){}
0072 
0073   // Copy constructor
0074   Clustering( const Clustering& inSystem ) :
0075     emitted(inSystem.emitted), emittor(inSystem.emittor),
0076     recoiler(inSystem.recoiler), partner(inSystem.partner),
0077     pTscale(inSystem.pTscale), flavRadBef(inSystem.flavRadBef),
0078     spinRad(inSystem.spinRad), spinEmt(inSystem.spinEmt),
0079     spinRec(inSystem.spinRec), spinRadBef(inSystem.spinRad),
0080     radBef(inSystem.radBef), recBef(inSystem.recBef),
0081     iPosInMother(inSystem.iPosInMother) {}
0082 
0083   // Constructor with input
0084   Clustering( int emtIn, int radIn, int recIn, int partnerIn,
0085     double pTscaleIn, int flavRadBefIn = 0, int spinRadIn = 9,
0086     int spinEmtIn = 9, int spinRecIn = 9, int spinRadBefIn = 9,
0087     int radBefIn = 0, int recBefIn = 0, map<int,int> posIn = map<int,int>())
0088     : emitted(emtIn), emittor(radIn), recoiler(recIn), partner(partnerIn),
0089       pTscale(pTscaleIn), flavRadBef(flavRadBefIn), spinRad(spinRadIn),
0090       spinEmt(spinEmtIn), spinRec(spinRecIn), spinRadBef(spinRadBefIn),
0091       radBef(radBefIn), recBef(recBefIn), iPosInMother(posIn) {}
0092 
0093   // Function to return pythia pT scale of clustering
0094   double pT() const { return pTscale; }
0095 
0096   // print for debug
0097   void list() const;
0098 
0099 };
0100 
0101 //==========================================================================
0102 
0103 // Declaration of History class
0104 //
0105 // A History object represents an event in a given step in the CKKW-L
0106 // clustering procedure. It defines a tree-like recursive structure,
0107 // where the root node represents the state with n jets as given by
0108 // the matrix element generator, and is characterized by the member
0109 // variable mother being null. The leaves on the tree corresponds to a
0110 // fully clustered paths where the original n-jets has been clustered
0111 // down to the Born-level state. Also states which cannot be clustered
0112 // down to the Born-level are possible - these will be called
0113 // incomplete. The leaves are characterized by the vector of children
0114 // being empty.
0115 
0116 class History {
0117 
0118 public:
0119 
0120   // The only constructor. Default arguments are used when creating
0121   // the initial history node. The \a depth is the maximum number of
0122   // clusterings requested. \a scalein is the scale at which the \a
0123   // statein was clustered (should be set to the merging scale for the
0124   // initial history node. \a beamAIn and beamBIn are needed to
0125   // calcutate PDF ratios, \a particleDataIn to have access to the
0126   // correct masses of particles. If \a isOrdered is true, the previous
0127   // clusterings has been ordered. \a is the PDF ratio for this
0128   // clustering (=1 for FSR clusterings). \a probin is the accumulated
0129   // probabilities for the previous clusterings, and \ mothin is the
0130   // previous history node (null for the initial node).
0131   History( int depthIn,
0132            double scalein,
0133            Event statein,
0134            Clustering c,
0135            MergingHooksPtr mergingHooksPtrIn,
0136            BeamParticle beamAIn,
0137            BeamParticle beamBIn,
0138            ParticleData* particleDataPtrIn,
0139            Info* infoPtrIn,
0140            PartonLevel* showersIn,
0141            CoupSM* coupSMPtrIn,
0142            bool isOrdered,
0143            bool isStronglyOrdered,
0144            bool isAllowed,
0145            bool isNextInInput,
0146            double probin,
0147            History * mothin);
0148 
0149   // The destructor deletes each child.
0150   ~History() {
0151     for ( int i = 0, N = children.size(); i < N; ++i ) delete children[i];
0152   }
0153 
0154   // Function to project paths onto desired paths.
0155   bool projectOntoDesiredHistories();
0156 
0157   // For CKKW-L, NL3 and UMEPS:
0158   // In the initial history node, select one of the paths according to
0159   // the probabilities. This function should be called for the initial
0160   // history node.
0161   // IN  trialShower*    : Previously initialised trialShower object,
0162   //                       to perform trial showering and as
0163   //                       repository of pointers to initialise alphaS
0164   //     PartonSystems*  : PartonSystems object needed to initialise
0165   //                       shower objects
0166   // OUT vector<double>  : (Sukadov) , (alpha_S ratios) , (PDF ratios)
0167   vector<double> weightCKKWL(PartonLevel* trial, AlphaStrong * asFSR,
0168     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN);
0169 
0170 
0171   // For default NL3:
0172   // Return weight of virtual correction and subtractive for NL3 merging
0173   vector<double> weightNL3Loop(PartonLevel* trial, double RN);
0174   // Return O(\alpha_s)-term of CKKWL-weight for NL3 merging
0175   vector<double> weightNL3First(PartonLevel* trial, AlphaStrong* asFSR,
0176     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
0177     Rndm* rndmPtr);
0178   vector<double> weightNL3Tree(PartonLevel* trial, AlphaStrong * asFSR,
0179     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN);
0180 
0181 
0182   // For UMEPS:
0183   vector<double> weightUMEPSTree(PartonLevel* trial, AlphaStrong * asFSR,
0184     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN);
0185   vector<double> weightUMEPSSubt(PartonLevel* trial, AlphaStrong * asFSR,
0186     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN);
0187 
0188 
0189   // For unitary NL3:
0190   vector<double> weightUNLOPSTree(PartonLevel* trial, AlphaStrong * asFSR,
0191     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
0192     int depthIn = -1);
0193   vector<double> weightUNLOPSSubt(PartonLevel* trial, AlphaStrong * asFSR,
0194     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
0195     int depthIn = -1);
0196   vector<double> weightUNLOPSLoop(PartonLevel* trial, AlphaStrong * asFSR,
0197      AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
0198      int depthIn = -1);
0199   vector<double> weightUNLOPSSubtNLO(PartonLevel* trial, AlphaStrong * asFSR,
0200     AlphaStrong * asISR, AlphaEM * aemFSR, AlphaEM * aemISR, double RN,
0201     int depthIn = -1);
0202   vector<double> weightUNLOPSFirst( int order, PartonLevel* trial,
0203     AlphaStrong* asFSR, AlphaStrong * asISR, AlphaEM * aemFSR,
0204     AlphaEM * aemISR, double RN, Rndm* rndmPtr );
0205 
0206   // Function to check if any allowed histories were found
0207   bool foundAllowedHistories() {
0208     return (children.size() > 0 && foundAllowedPath); }
0209   // Function to check if any ordered histories were found
0210   bool foundOrderedHistories() {
0211     return (children.size() > 0 && foundOrderedPath); }
0212   // Function to check if any ordered histories were found
0213   bool foundCompleteHistories() {
0214     return (children.size() > 0 && foundCompletePath); }
0215 
0216   // Function to set the state with complete scales for evolution
0217   void getStartingConditions( const double RN, Event& outState );
0218   // Function to get the state with complete scales for evolution
0219   bool getClusteredEvent( const double RN, int nSteps, Event& outState);
0220   // Function to get the first reclustered state above the merging scale.
0221   bool getFirstClusteredEventAboveTMS( const double RN, int nDesired,
0222     Event& process, int & nPerformed, bool updateProcess = true );
0223   // Function to return the depth of the history (i.e. the number of
0224   // reclustered splittings)
0225   int nClusterings();
0226 
0227   // Function to get the lowest multiplicity reclustered event
0228   Event lowestMultProc( const double RN) {
0229     // Return lowest multiplicity state
0230     return (select(RN)->state);
0231   }
0232 
0233   // Calculate and return pdf ratio
0234   double getPDFratio( int side, bool forSudakov, bool useHardPDF,
0235                       int flavNum, double xNum, double muNum,
0236                       int flavDen, double xDen, double muDen);
0237 
0238   // Envelope function that calls the recursive getWeakProb.
0239   double getWeakProb();
0240 
0241   // Recursive function that returns the weak probability for the given path.
0242   // Mode refers to which ME correction to use, 1 = sChannel, 2 = gluon
0243   // channel, 3 = double quark t-channel, 4 is double quark u-channel.
0244   double getWeakProb(vector<int>& mode, vector<Vec4>& mom,
0245      vector<int> fermionLines);
0246 
0247   // return the weak probability of a single reclustering.
0248   // Mode refers to which ME correction to use, 1 = sChannel, 2 = gluon
0249   // channel, 3 = double quark t-channel, 4 is double quark u-channel.
0250   double getSingleWeakProb(vector<int> &mode, vector<Vec4> &mom,
0251     vector<int> fermionLines);
0252 
0253   // Find map between indecies in the current state and the state after
0254   // the splitting.
0255   // NOT IMPLEMENTED FOR MULTIPLE W/Z/GAMMA (NEED TO HAVE A WAY TO
0256   // IDENTIFY THEM).
0257   void findStateTransfer(map<int,int> &transfer);
0258 
0259   // Function to print the history that would be chosen from the random number
0260   // RN. Mainly for debugging.
0261   void printHistory( const double RN );
0262   // Function to print the states in a history, starting from the hard process.
0263   // Mainly for debugging.
0264   void printStates();
0265 
0266   // Make Pythia class friend
0267   friend class Pythia;
0268   // Make Merging class friend
0269   friend class Merging;
0270 
0271 private:
0272 
0273   // Number of trial emission to use for calculating the average number of
0274   // emissions
0275   static const int NTRIAL;
0276 
0277   // Function to set all scales in the sequence of states. This is a
0278   // wrapper routine for setScales and setEventScales methods
0279   void setScalesInHistory();
0280 
0281   // Function to find the index (in the mother histories) of the
0282   // child history, thus providing a way access the path from both
0283   // initial history (mother == 0) and final history (all children == 0)
0284   // IN vector<int> : The index of each child in the children vector
0285   //                  of the current history node will be saved in
0286   //                  this vector
0287   // NO OUTPUT
0288   void findPath(vector<int>& out);
0289 
0290   // Functions to set the  parton production scales and enforce
0291   // ordering on the scales of the respective clusterings stored in
0292   // the History node:
0293   // Method will start from lowest multiplicity state and move to
0294   // higher states, setting the production scales the shower would
0295   // have used.
0296   // When arriving at the highest multiplicity, the method will switch
0297   // and go back in direction of lower states to check and enforce
0298   // ordering for unordered histories.
0299   // IN vector<int> : Vector of positions of the chosen child
0300   //                  in the mother history to allow to move
0301   //                  in direction initial->final along path
0302   //    bool        : True: Move in direction low->high
0303   //                       multiplicity and set production scales
0304   //                  False: Move in direction high->low
0305   //                       multiplicity and check and enforce
0306   //                       ordering
0307   // NO OUTPUT
0308   void setScales( vector<int> index, bool forward);
0309 
0310   // Function to find a particle in all higher multiplicity events
0311   // along the history path and set its production scale to the input
0312   // scale
0313   // IN  int iPart       : Parton in refEvent to be checked / rescaled
0314   //     Event& refEvent : Reference event for iPart
0315   //     double scale    : Scale to be set as production scale for
0316   //                       unchanged copies of iPart in subsequent steps
0317   void scaleCopies(int iPart, const Event& refEvent, double rho);
0318 
0319   // Function to set the OVERALL EVENT SCALES [=state.scale()] to
0320   // the scale of the last clustering
0321   // NO INPUT
0322   // NO OUTPUT
0323   void setEventScales();
0324 
0325   // Function to print information on the reconstructed scales in one path.
0326   // For debug only.
0327   void printScales() { if ( mother ) mother->printScales();
0328     cout << " size " << state.size() << " scale " << scale << " clusterIn "
0329       << clusterIn.pT() << " state.scale() " << state.scale() << endl; }
0330 
0331   // Function to project paths onto desired paths.
0332   bool trimHistories();
0333   // Function to tag history for removal.
0334   void remove(){ doInclude = false; }
0335   // Function to return flag of allowed histories to choose from.
0336   bool keep(){ return doInclude; }
0337   // Function implementing checks on a paths, for deciding if the path should
0338   // be considered valid or not.
0339   bool keepHistory();
0340   // Function to check if a path is ordered in evolution pT.
0341   bool isOrderedPath( double maxscale );
0342 
0343   bool followsInputPath();
0344 
0345   // Function to check if all reconstucted states in a path pass the merging
0346   // scale cut.
0347   bool allIntermediateAboveRhoMS( double rhoms, bool good = true );
0348   // Function to check if any ordered paths were found (and kept).
0349   bool foundAnyOrderedPaths();
0350 
0351   // Functions to return the z value of the last ISR splitting
0352   // NO INPUT
0353   // OUTPUT double : z value of last ISR splitting in history
0354   double zISR();
0355 
0356   // Functions to return the z value of the last FSR splitting
0357   // NO INPUT
0358   // OUTPUT double : z value of last FSR splitting in history
0359   double zFSR();
0360 
0361   // Functions to return the pT scale of the last ISR splitting
0362   // NO INPUT
0363   // OUTPUT double : pT scale of last ISR splitting in history
0364   double pTISR();
0365 
0366   // Functions to return the pT scale of the last FSR splitting
0367   // NO INPUT
0368   // OUTPUT double : pT scale of last FSR splitting in history
0369   double pTFSR();
0370 
0371   // Functions to return the event with nSteps additional partons
0372   // INPUT  int   : Number of splittings in the event,
0373   //                as counted from core 2->2 process
0374   // OUTPUT Event : event with nSteps additional partons
0375   Event clusteredState( int nSteps);
0376 
0377   // Function to choose a path from all paths in the tree
0378   // according to their splitting probabilities
0379   // IN double    : Random number
0380   // OUT History* : Leaf of history path chosen
0381   History * select(double rnd);
0382 
0383   // For a full path, find the weight calculated from the ratio of
0384   // couplings, the no-emission probabilities, and possible PDF
0385   // ratios. This function should only be called for the last history
0386   // node of a full path.
0387   // IN  TimeShower : Already initialised shower object to be used as
0388   //                  trial shower
0389   //     double     : alpha_s value used in ME calculation
0390   //     double     : Maximal mass scale of the problem (e.g. E_CM)
0391   //     AlphaStrong: Initialised shower alpha_s object for FSR alpha_s
0392   //                  ratio calculation
0393   //     AlphaStrong: Initialised shower alpha_s object for ISR alpha_s
0394   //                  ratio calculation (can be different from previous)
0395   vector<double> weightTree(PartonLevel* trial, double as0, double aem0,
0396     double maxscale, double pdfScale, AlphaStrong * asFSR, AlphaStrong * asISR,
0397     AlphaEM * aemFSR, AlphaEM * aemISR, vector<double>& asWeight,
0398     vector<double>& aemWeight, vector<double>& pdfWeight);
0399 
0400   // Function to return the \alpha_s-ratio part of the CKKWL weight.
0401   vector<double> weightTreeAlphaS( double as0, AlphaStrong * asFSR,
0402     AlphaStrong * asISR, int njetMax = -1, bool asVarInME = false );
0403   // Function to return the \alpha_em-ratio part of the CKKWL weight.
0404   vector<double> weightTreeAlphaEM( double aem0, AlphaEM * aemFSR,
0405     AlphaEM * aemISR, int njetMax = -1 );
0406   // Function to return the PDF-ratio part of the CKKWL weight.
0407   vector<double> weightTreePDFs( double maxscale, double pdfScale,
0408     int njetMax = -1 );
0409   // Function to return the no-emission probability part of the CKKWL weight.
0410   vector<double> weightTreeEmissions( PartonLevel* trial, int type,
0411     int njetMin, int njetMax, double maxscale );
0412 
0413   // Function to generate the O(\alpha_s)-term of the CKKWL-weight
0414   double weightFirst(PartonLevel* trial, double as0, double muR,
0415     double maxscale, AlphaStrong * asFSR, AlphaStrong * asISR, Rndm* rndmPtr );
0416 
0417   // Function to generate the O(\alpha_s)-term of the \alpha_s-ratios
0418   // appearing in the CKKWL-weight.
0419   double weightFirstAlphaS( double as0, double muR, AlphaStrong * asFSR,
0420     AlphaStrong * asISR);
0421   // Function to generate the O(\alpha_em)-term of the \alpha_em-ratios
0422   // appearing in the CKKWL-weight.
0423   double weightFirstAlphaEM( double aem0, double muR, AlphaEM * aemFSR,
0424     AlphaEM * aemISR);
0425   // Function to generate the O(\alpha_s)-term of the PDF-ratios
0426   // appearing in the CKKWL-weight.
0427   double weightFirstPDFs( double as0, double maxscale, double pdfScale,
0428     Rndm* rndmPtr );
0429   // Function to generate the O(\alpha_s)-term of the no-emission
0430   // probabilities appearing in the CKKWL-weight.
0431   double weightFirstEmissions(PartonLevel* trial, double as0, double maxscale,
0432     AlphaStrong * asFSR, AlphaStrong * asISR, bool fixpdf, bool fixas );
0433 
0434   // Function to return the default factorisation scale of the hard process.
0435   double hardFacScale(const Event& event);
0436   // Function to return the default renormalisation scale of the hard process.
0437   double hardRenScale(const Event& event);
0438 
0439   // Perform a trial shower using the \a pythia object between
0440   // maxscale down to this scale and return the corresponding Sudakov
0441   // form factor.
0442   // IN  trialShower : Shower object used as trial shower
0443   //     double     : Maximum scale for trial shower branching
0444   // OUT  0.0       : trial shower emission outside allowed pT range
0445   //      1.0       : trial shower successful (any emission was below
0446   //                  the minimal scale )
0447   vector<double> doTrialShower(PartonLevel* trial, int type, double maxscale,
0448     double minscale = 0.);
0449 
0450   // Function to bookkeep the indices of weights generated in countEmissions
0451   bool updateind(vector<int> & ind, int i, int N);
0452 
0453   // Function to count number of emissions between two scales for NLO merging
0454   vector<double> countEmissions(PartonLevel* trial, double maxscale,
0455     double minscale, int showerType, double as0, AlphaStrong * asFSR,
0456     AlphaStrong * asISR, int N, bool fixpdf, bool fixas);
0457 
0458   // Function to integrate PDF ratios between two scales over x and t,
0459   // where the PDFs are always evaluated at the lower t-integration limit
0460   double monteCarloPDFratios(int flav, double x, double maxScale,
0461            double minScale, double pdfScale, double asME, Rndm* rndmPtr);
0462 
0463   // Default: Check if a ordered (and complete) path has been found in
0464   // the initial node, in which case we will no longer be interested in
0465   // any unordered paths.
0466   bool onlyOrderedPaths();
0467 
0468   // Check if a strongly ordered (and complete) path has been found in the
0469   // initial node, in which case we will no longer be interested in
0470   // any unordered paths.
0471   bool onlyStronglyOrderedPaths();
0472 
0473   // Check if an allowed (according to user-criterion) path has been found in
0474   // the initial node, in which case we will no longer be interested in
0475   // any forbidden paths.
0476   bool onlyAllowedPaths();
0477 
0478   // When a full path has been found, register it with the initial
0479   // history node.
0480   // IN  History : History to be registered as path
0481   //     bool    : Specifying if clusterings so far were ordered
0482   //     bool    : Specifying if path is complete down to 2->2 process
0483   // OUT true if History object forms a plausible path (eg prob>0 ...)
0484   bool registerPath(History & l, bool isOrdered, bool isStronglyOrdered,
0485          bool isAllowed, bool isComplete);
0486 
0487   // For the history-defining state (and if necessary interfering
0488   // states), find all possible clusterings.
0489   // NO INPUT
0490   // OUT vector of all (rad,rec,emt) systems
0491   vector<Clustering> getAllQCDClusterings();
0492 
0493   // For one given state, find all possible clusterings.
0494   // IN  Event : state to be investigated
0495   // OUT vector of all (rad,rec,emt) systems in the state
0496   vector<Clustering> getQCDClusterings( const Event& event);
0497 
0498   // Function to construct (rad,rec,emt) triples from the event
0499   // IN  int   : Position of Emitted in event record for which
0500   //             dipoles should be constructed
0501   //     int   : Colour topogy to be tested
0502   //             1= g -> qqbar, causing 2 -> 2 dipole splitting
0503   //             2= q(bar) -> q(bar) g && g -> gg,
0504   //              causing a 2 -> 3 dipole splitting
0505   //     Event : event record to be checked for ptential partners
0506   // OUT vector of all allowed radiator+recoiler+emitted triples
0507   vector<Clustering> findQCDTriple (int emtTagIn, int colTopIn,
0508                        const Event& event, vector<int> posFinalPartn,
0509                        vector <int> posInitPartn );
0510 
0511   vector<Clustering> getAllEWClusterings();
0512   vector<Clustering> getEWClusterings( const Event& event);
0513   vector<Clustering> findEWTripleW( int emtTagIn, const Event& event,
0514                        vector<int> posFinalPartn, vector<int> posInitPartn );
0515   vector<Clustering> findEWTripleZ( int emtTagIn, const Event& event,
0516                        vector<int> posFinalPartn, vector<int> posInitPartn );
0517 
0518   vector<Clustering> getAllSQCDClusterings();
0519   vector<Clustering> getSQCDClusterings( const Event& event);
0520   vector<Clustering> findSQCDTriple (int emtTagIn, int colTopIn,
0521                        const Event& event, vector<int> posFinalPartn,
0522                        vector <int> posInitPartn );
0523 
0524   // Function to attach (spin-dependent duplicates of) a clustering.
0525   void attachClusterings (vector<Clustering>& clus, int iEmt, int iRad,
0526     int iRec, int iPartner, double pT, const Event& event);
0527 
0528   // Calculate and return the probability of a clustering.
0529   // IN  Clustering : rad,rec,emt - System for which the splitting
0530   //                  probability should be calcuated
0531   // OUT splitting probability
0532   double getProb(const Clustering & SystemIn);
0533 
0534   // Set up the beams (fill the beam particles with the correct
0535   // current incoming particles) to allow calculation of splitting
0536   // probability.
0537   // For interleaved evolution, set assignments dividing PDFs into
0538   // sea and valence content. This assignment is, until a history path
0539   // is chosen and a first trial shower performed, not fully correct
0540   // (since content is chosen form too high x and too low scale). The
0541   // assignment used for reweighting will be corrected after trial
0542   // showering
0543   void setupBeams();
0544 
0545   // Calculate the PDF ratio used in the argument of the no-emission
0546   // probability.
0547   double pdfForSudakov();
0548 
0549   // Calculate the hard process matrix element to include in the selection
0550   // probability.
0551   double hardProcessME( const Event& event);
0552 
0553   // Perform the clustering of the current state and return the
0554   // clustered state.
0555   // IN Clustering : rad,rec,emt triple to be clustered to two partons
0556   // OUT clustered state
0557   Event cluster( Clustering & inSystem);
0558 
0559   // Function to get the flavour of the radiator before the splitting
0560   // for clustering
0561   // IN  int   : Position of the radiator after the splitting, in the event
0562   //     int   : Position of the emitted after the splitting, in the event
0563   //     Event : Reference event
0564   // OUT int   : Flavour of the radiator before the splitting
0565   int getRadBeforeFlav(const int radAfter, const int emtAfter,
0566         const Event& event);
0567 
0568   // Function to get the spin of the radiator before the splitting
0569   // IN int  : Spin of the radiator after the splitting
0570   //    int  : Spin of the emitted after the splitting
0571   // OUT int : Spin of the radiator before the splitting
0572   int getRadBeforeSpin(const int radAfter, const int emtAfter,
0573         const int spinRadAfter, const int spinEmtAfter,
0574         const Event& event);
0575 
0576   // Function to get the colour of the radiator before the splitting
0577   // for clustering
0578   // IN  int   : Position of the radiator after the splitting, in the event
0579   //     int   : Position of the emitted after the splitting, in the event
0580   //     Event : Reference event
0581   // OUT int   : Colour of the radiator before the splitting
0582   int getRadBeforeCol(const int radAfter, const int emtAfter,
0583         const Event& event);
0584 
0585   // Function to get the anticolour of the radiator before the splitting
0586   // for clustering
0587   // IN  int   : Position of the radiator after the splitting, in the event
0588   //     int   : Position of the emitted after the splitting, in the event
0589   //     Event : Reference event
0590   // OUT int   : Anticolour of the radiator before the splitting
0591   int getRadBeforeAcol(const int radAfter, const int emtAfter,
0592         const Event& event);
0593 
0594   // Function to get the parton connected to in by a colour line
0595   // IN  int   : Position of parton for which partner should be found
0596   //     Event : Reference event
0597   // OUT int   : If a colour line connects the "in" parton with another
0598   //             parton, return the Position of the partner, else return 0
0599   int getColPartner(const int in, const Event& event);
0600 
0601   // Function to get the parton connected to in by an anticolour line
0602   // IN  int   : Position of parton for which partner should be found
0603   //     Event : Reference event
0604   // OUT int   : If an anticolour line connects the "in" parton with another
0605   //             parton, return the Position of the partner, else return 0
0606   int getAcolPartner(const int in, const Event& event);
0607 
0608   // Function to get the list of partons connected to the particle
0609   // formed by reclusterinf emt and rad by colour and anticolour lines
0610   // IN  int          : Position of radiator in the clustering
0611   // IN  int          : Position of emitted in the clustering
0612   //     Event        : Reference event
0613   // OUT vector<int>  : List of positions of all partons that are connected
0614   //                    to the parton that will be formed
0615   //                    by clustering emt and rad.
0616   vector<int> getReclusteredPartners(const int rad, const int emt,
0617     const Event& event);
0618 
0619   // Function to extract a chain of colour-connected partons in
0620   // the event
0621   // IN     int          : Type of parton from which to start extracting a
0622   //                       parton chain. If the starting point is a quark
0623   //                       i.e. flavType = 1, a chain of partons that are
0624   //                       consecutively connected by colour-lines will be
0625   //                       extracted. If the starting point is an antiquark
0626   //                       i.e. flavType =-1, a chain of partons that are
0627   //                       consecutively connected by anticolour-lines
0628   //                       will be extracted.
0629   // IN      int         : Position of the parton from which a
0630   //                       colour-connected chain should be derived
0631   // IN      Event       : Refernence event
0632   // IN/OUT  vector<int> : Partons that should be excluded from the search.
0633   // OUT     vector<int> : Positions of partons along the chain
0634   // OUT     bool        : Found singlet / did not find singlet
0635   bool getColSinglet(const int flavType, const int iParton,
0636     const Event& event, vector<int>& exclude,
0637     vector<int>& colSinglet);
0638 
0639   // Function to check that a set of partons forms a colour singlet
0640   // IN  Event       : Reference event
0641   // IN  vector<int> : Positions of the partons in the set
0642   // OUT bool        : Is a colour singlet / is not
0643   bool isColSinglet( const Event& event, vector<int> system);
0644   // Function to check that a set of partons forms a flavour singlet
0645   // IN  Event       : Reference event
0646   // IN  vector<int> : Positions of the partons in the set
0647   // IN  int         : Flavour of all the quarks in the set, if
0648   //                   all quarks in a set should have a fixed flavour
0649   // OUT bool        : Is a flavour singlet / is not
0650   bool isFlavSinglet( const Event& event,
0651     vector<int> system, int flav=0);
0652 
0653   // Function to properly colour-connect the radiator to the rest of
0654   // the event, as needed during clustering
0655   // IN  Particle& : Particle to be connected
0656   //     Particle  : Recoiler forming a dipole with Radiator
0657   //     Event     : event to which Radiator shall be appended
0658   // OUT true               : Radiator could be connected to the event
0659   //     false              : Radiator could not be connected to the
0660   //                          event or the resulting event was
0661   //                          non-valid
0662   bool connectRadiator( Particle& radiator, const int radType,
0663                         const Particle& recoiler, const int recType,
0664                         const Event& event );
0665 
0666   // Function to find a colour (anticolour) index in the input event
0667   // IN  int col       : Colour tag to be investigated
0668   //     int iExclude1 : Identifier of first particle to be excluded
0669   //                     from search
0670   //     int iExclude2 : Identifier of second particle to be excluded
0671   //                     from  search
0672   //     Event event   : event to be searched for colour tag
0673   //     int type      : Tag to define if col should be counted as
0674   //                      colour (type = 1) [->find anti-colour index
0675   //                                         contracted with col]
0676   //                      anticolour (type = 2) [->find colour index
0677   //                                         contracted with col]
0678   // OUT int           : Position of particle in event record
0679   //                     contraced with col [0 if col is free tag]
0680   int FindCol(int col, int iExclude1, int iExclude2,
0681               const Event& event, int type, bool isHardIn);
0682 
0683   // Function to in the input event find a particle with quantum
0684   // numbers matching those of the input particle
0685   // IN  Particle : Particle to be searched for
0686   //     Event    : Event to be searched in
0687   // OUT int      : > 0 : Position of matching particle in event
0688   //                < 0 : No match in event
0689   int FindParticle( const Particle& particle, const Event& event,
0690     bool checkStatus = true );
0691 
0692   // Function to check if rad,emt,rec triple is allowed for clustering
0693   // IN int rad,emt,rec,partner : Positions (in event record) of the three
0694   //                      particles considered for clustering, and the
0695   //                      correct colour-connected recoiler (=partner)
0696   //    Event event     : Reference event
0697   bool allowedClustering( int rad, int emt, int rec, int partner,
0698     const Event& event );
0699 
0700   // Function to check if rad,emt,rec triple is results in
0701   // colour singlet radBefore+recBefore
0702   // IN int rad,emt,rec : Positions (in event record) of the three
0703   //                      particles considered for clustering
0704   //    Event event     : Reference event
0705   bool isSinglett( int rad, int emt, int rec, const Event& event );
0706 
0707   // Function to check if event is sensibly constructed: Meaning
0708   // that all colour indices are contracted and that the charge in
0709   // initial and final states matches
0710   // IN  event : event to be checked
0711   // OUT TRUE  : event is properly construced
0712   //     FALSE : event not valid
0713   bool validEvent( const Event& event );
0714 
0715   // Function to check whether two clusterings are identical, used
0716   // for finding the history path in the mother -> children direction
0717   bool equalClustering( Clustering clus1 , Clustering clus2 );
0718 
0719   // Chose dummy scale for event construction. By default, choose
0720   //     sHat     for 2->Boson(->2)+ n partons processes and
0721   //     M_Boson  for 2->Boson(->)             processes
0722   double choseHardScale( const Event& event ) const;
0723 
0724   // If the state has an incoming hadron return the flavour of the
0725   // parton entering the hard interaction. Otherwise return 0
0726   int getCurrentFlav(const int) const;
0727 
0728    // If the state has an incoming hadron return the x-value for the
0729    // parton entering the hard interaction. Otherwise return 0.
0730   double getCurrentX(const int) const;
0731 
0732   double getCurrentZ(const int rad, const int rec, const int emt,
0733     int idRadBef = 0) const;
0734 
0735   // Function to compute "pythia pT separation" from Particle input
0736   double pTLund(const Event& event, int radAfterBranch, int emtAfterBranch,
0737     int recAfterBranch, int showerType, int idRadBef = 0);
0738 
0739   // Function to return the position of the initial line before (or after)
0740   // a single (!) splitting.
0741   int posChangedIncoming(const Event& event, bool before);
0742 
0743   // Function to give back the ratio of PDFs and PDF * splitting kernels
0744   // needed to convert a splitting at scale pdfScale, chosen with running
0745   // PDFs, to a splitting chosen with PDFs at a fixed scale mu. As needed to
0746   // properly count emissions.
0747   double pdfFactor( const Event& event, const int type, double pdfScale,
0748     double mu );
0749 
0750   // Function giving the product of splitting kernels and PDFs so that the
0751   // resulting flavour is given by flav. This is used as a helper routine
0752   // to dgauss
0753   double integrand(int flav, double x, double scaleInt, double z);
0754 
0755   // Function providing a list of possible new flavours after a w emssion
0756   // from the input flavour.
0757   vector<int> posFlavCKM(int flav);
0758 
0759   // Check if the new flavour structure is possible.
0760   // If clusType is 1 final clustering is assumed, otherwise initial clustering
0761   // is assumed.
0762   bool checkFlavour(vector<int>& flavCounts, int flavRad, int flavRadBef,
0763     int clusType);
0764 
0765   // Check if the weak recoil structure is allowed.
0766   bool checkWeakRecoils(map<int,int> &allowedRecoils, bool isFirst = false);
0767 
0768   // Find the recoiler for an ISR scattered weak particle.
0769 
0770   int findISRRecoiler();
0771 
0772   // Reverse the boost carried out by the ISR.
0773   // The three first momenta are given by the ME,
0774   // the last two are filled in by this function.
0775   void reverseBoostISR(Vec4& pMother, Vec4& pSister, Vec4& pPartner,
0776     Vec4& pDaughter, Vec4& pRecoiler, int sign, double eCM, double& phi);
0777 
0778   // Check if an event reclustered into a 2 -> 2 dijet.
0779   // (Only enabled if W reclustering is used).
0780   bool isQCD2to2(const Event& event);
0781 
0782   // Check if an event reclustered into a 2 -> 1 Drell-Yan.
0783   // (Only enabled if W reclustering is used).
0784   bool isEW2to1(const Event& event);
0785 
0786   // Set selected child indices.
0787   void setSelectedChild();
0788 
0789   // Setup the weak dipole showers.
0790   void setupSimpleWeakShower(int nSteps);
0791 
0792   // Update weak dipoles after an emission.
0793   void transferSimpleWeakShower(vector<int> &mode, vector<Vec4> &mom,
0794     vector<int> fermionLines, vector<pair<int,int> > &dipoles, int nSteps);
0795 
0796   // Update the weak modes after an emission.
0797   vector<int> updateWeakModes(vector<int>& weakModes,
0798     map<int,int>& stateTransfer);
0799 
0800   // Update the fermion lines for the 2 -> 2 process. This is needed for
0801   // the weak probabilities.
0802   vector<int> updateWeakFermionLines(vector<int> fermionLines,
0803     map<int,int>& stateTransfer);
0804 
0805   // Update the list of weak dipoles. This is needed to setup the PS correctly.
0806   vector<pair<int,int> > updateWeakDipoles(vector<pair<int,int> > &dipoles,
0807     map<int,int>& stateTransfer);
0808 
0809   // Setup the hard process information needed for calculating weak
0810   // probabilities and setting up the shower.
0811   void setupWeakHard(vector<int>& mode, vector<int>& fermionLines,
0812     vector<Vec4>& mom);
0813 
0814   // Functions to retrieve scale information from external showers.
0815   double getShowerPluginScale(const Event& event, int rad, int emt, int rec,
0816     string key, double scalePythia);
0817 
0818   //----------------------------------------------------------------------//
0819   // Class members.
0820   //----------------------------------------------------------------------//
0821 
0822   // The state of the event correponding to this step in the
0823   // reconstruction.
0824   Event state;
0825 
0826   // The previous step from which this step has been clustered. If
0827   // null, this is the initial step with the n-jet state generated by
0828   // the matrix element.
0829   History * mother;
0830 
0831   // The different steps corresponding to possible clusterings of this
0832   // state.
0833   vector<History *> children;
0834 
0835   // After a path is selected, store the child index.
0836   int selectedChild;
0837 
0838   // The different paths which have been reconstructed indexed with
0839   // the (incremental) corresponding probability. This map is empty
0840   // unless this is the initial step (mother == 0).
0841   map<double,History *> paths;
0842 
0843   // The sum of the probabilities of the full paths. This is zero
0844   // unless this is the initial step (mother == 0).
0845   double sumpath;
0846 
0847   // The different allowed paths after projection, indexed with
0848   // the (incremental) corresponding probability. This map is empty
0849   // unless this is the initial step (mother == 0).
0850   map<double,History *> goodBranches, badBranches;
0851   // The sum of the probabilities of allowed paths after projection. This is
0852   // zero unless this is the initial step (mother == 0).
0853   double sumGoodBranches, sumBadBranches;
0854 
0855   // This is set true if an ordered (and complete) path has been found
0856   // and inserted in paths.
0857   bool foundOrderedPath;
0858 
0859   // This is set true if a strongly ordered (and complete) path has been found
0860   // and inserted in paths.
0861   bool foundStronglyOrderedPath;
0862 
0863   // This is set true if an allowed (according to a user criterion) path has
0864   // been found and inserted in paths.
0865   bool foundAllowedPath;
0866 
0867   // This is set true if a complete (with the required number of
0868   // clusterings) path has been found and inserted in paths.
0869   bool foundCompletePath;
0870 
0871   // The scale of this step, corresponding to clustering which
0872   // constructed the corresponding state (or the merging scale in case
0873   // mother == 0).
0874   double scale;
0875 
0876   // Flag indicating if a clustering in the construction of all histories is
0877   // the next clustering demanded by inout clusterings in LesHouches 2.0
0878   // accord.
0879   bool nextInInput;
0880 
0881   // The probability associated with this step and the previous steps.
0882   double prob;
0883 
0884   // The partons and scale of the last clustering.
0885   Clustering clusterIn;
0886   int iReclusteredOld, iReclusteredNew;
0887 
0888   // Flag to include the path amongst allowed paths.
0889   bool doInclude;
0890 
0891   // Pointer to MergingHooks object to get all the settings.
0892   MergingHooksPtr mergingHooksPtr;
0893 
0894    // The default constructor is private.
0895   History() : mother(), selectedChild(), sumpath(), sumGoodBranches(),
0896     sumBadBranches(), foundOrderedPath(), foundStronglyOrderedPath(),
0897     foundAllowedPath(), foundCompletePath(), scale(), nextInInput(), prob(),
0898     iReclusteredOld(), iReclusteredNew(), doInclude(), mergingHooksPtr(),
0899     particleDataPtr(), infoPtr(), loggerPtr(), showers(), coupSMPtr(),
0900     sumScalarPT(), probMaxSave(), depth(), minDepthSave() {}
0901 
0902   // The copy-constructor is private.
0903   History(const History &) {}
0904 
0905   // The assignment operator is private.
0906   History & operator=(const History &) {
0907     return *this;
0908   }
0909 
0910   // BeamParticle to get access to PDFs
0911   BeamParticle beamA;
0912   BeamParticle beamB;
0913   // ParticleData needed to initialise the shower AND to get the
0914   // correct masses of partons needed in calculation of probability
0915   ParticleData* particleDataPtr;
0916 
0917   // Info object to have access to all information read from LHE file
0918   Info* infoPtr;
0919 
0920   // Logger object.
0921   Logger* loggerPtr;
0922 
0923   // Class for calculation weak shower ME.
0924   SimpleWeakShowerMEs simpleWeakShowerMEs;
0925 
0926   // Pointer to showers, to simplify external clusterings.
0927   PartonLevel* showers;
0928 
0929   // Pointer to standard model couplings.
0930   CoupSM*     coupSMPtr;
0931 
0932   // Minimal scalar sum of pT used in Herwig to choose history
0933   double sumScalarPT;
0934 
0935   double probMaxSave;
0936   double probMax() {
0937     if (mother) return mother->probMax();
0938     return probMaxSave;
0939   }
0940   void updateProbMax(double probIn, bool isComplete = false) {
0941     if (mother) mother->updateProbMax(probIn, isComplete);
0942     if (!isComplete && !foundCompletePath) return;
0943     if (abs(probIn) > probMaxSave) probMaxSave = probIn;
0944   }
0945 
0946   int depth, minDepthSave;
0947   int minDepth() {
0948     if ( mother ) return mother->minDepth();
0949     return minDepthSave;
0950   }
0951   void updateMinDepth(int depthIn) {
0952     if ( mother ) return mother->updateMinDepth(depthIn);
0953     minDepthSave = (minDepthSave>0) ? min(minDepthSave,depthIn) : depthIn;
0954   }
0955 
0956 };
0957 
0958 //==========================================================================
0959 
0960 } // end namespace Pythia8
0961 
0962 #endif // end Pythia8_History_H