Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 #ifndef HERWIG_FxFxHandler_H
0003 #define HERWIG_FxFxHandler_H
0004 //
0005 // This is the declaration of the FxFxHandler class.
0006 //
0007 
0008 #include "Herwig/Shower/QTilde/QTildeShowerHandler.h"
0009 #include "Herwig/Shower/ShowerHandler.h"
0010 #include "ThePEG/Config/Pointers.h"
0011 #include "Herwig/Shower/ShowerAlpha.h"
0012 #include "fastjet/PseudoJet.hh"
0013 #include "fastjet/ClusterSequence.hh"
0014 #include "ThePEG/Utilities/CompSelector.h"
0015 #include "ThePEG/Utilities/XSecStat.h"
0016 
0017 namespace Herwig {
0018   class FxFxHandler;
0019 }
0020 
0021 //declaration of thepeg ptr
0022 namespace ThePEG {
0023   ThePEG_DECLARE_POINTERS(Herwig::FxFxHandler,FxFxHandlerPtr);
0024 }
0025 
0026 namespace Herwig {
0027 
0028 using namespace ThePEG;
0029 
0030   typedef vector< string > split_vector_type;
0031 
0032 /**
0033  * Here is the documentation of the FxFxHandler class.
0034  *
0035  * @see \ref FxFxHandlerInterfaces "The interfaces"
0036  * defined for FxFxHandler.
0037  */
0038 class FxFxHandler: public QTildeShowerHandler {
0039 
0040   /**
0041    * FxFxHandler should have access to our private parts.
0042    */
0043   friend class FxFxEventHandler;
0044 
0045   friend class FxFxReader;
0046 
0047 
0048 public:
0049 
0050   /**
0051    * The default constructor.
0052    */
0053   FxFxHandler();
0054 
0055 public:
0056 
0057   /** @name Functions used by the persistent I/O system. */
0058   //@{
0059   /**
0060    * Function used to write out object persistently.
0061    * @param os the persistent output stream written to.
0062    */
0063   void persistentOutput(PersistentOStream & os) const;
0064 
0065   /**
0066    * Function used to read in object persistently.
0067    * @param is the persistent input stream read from.
0068    * @param version the version number of the object when written.
0069    */
0070   void persistentInput(PersistentIStream & is, int version);
0071   //@}
0072 
0073   /**
0074    * The standard Init function used to initialize the interfaces.
0075    * Called exactly once for each class by the class description system
0076    * before the main function starts or
0077    * when this class is dynamically loaded.
0078    */
0079   static void Init();
0080 
0081 protected:
0082 
0083   /** @name Standard Interfaced functions. */
0084   //@{
0085   /**
0086    * Finalize the object
0087    */
0088   virtual void dofinish();
0089 
0090   /**
0091    * Initialize this object after the setup phase before saving an
0092    * EventGenerator to disk.
0093    * @throws InitException if object could not be initialized properly.
0094    */
0095   virtual void doinit();
0096 
0097   /**
0098    * Initialize this object. Called in the run phase just before
0099    * a run begins.
0100    */
0101   virtual void doinitrun();
0102   //@}
0103 
0104 public:
0105   /**
0106    * Hook to allow vetoing of event after showering hard sub-process
0107    * as in e.g. MLM merging.
0108    */
0109   virtual bool showerHardProcessVeto() const;
0110 
0111  /**
0112    * information for FxFx merging
0113    */
0114   mutable int npLO_;
0115   mutable int npNLO_;
0116 
0117  /**
0118    * information for tree-level merging
0119    */
0120   mutable vector<double> ptclust_;
0121 
0122 protected:
0123 
0124   /** @name Clone Methods. */
0125   //@{
0126   /**
0127    * Make a simple clone of this object.
0128    * @return a pointer to the new object.
0129    */
0130   virtual IBPtr clone() const;
0131 
0132   /** Make a clone of this object, possibly modifying the cloned object
0133    * to make it sane.
0134    * @return a pointer to the new object.
0135    */
0136   virtual IBPtr fullclone() const;
0137   //@}
0138 
0139 private:
0140 
0141   /*
0142    * whether a heavy quark has been found in the merging
0143    */
0144   mutable bool hvqfound = false;
0145   
0146   /* 
0147    * Run MLM jet-parton matching on the 'extra' jets.
0148    */
0149   bool lightJetPartonVeto();
0150   
0151   /* 
0152    * Function that calculates deltaR between a parton and a jet
0153    */
0154   double partonJetDeltaR(ThePEG::tPPtr partonptr, LorentzMomentum jetmom) const;
0155 
0156     
0157   /* 
0158    * Function that calculates deltaR between two jets
0159    */
0160   double partonJetDeltaR(LorentzMomentum jetmom1, LorentzMomentum jetmom2) const;
0161  
0162  /**
0163    * Find jets using the FastJet package on particlesToCluster_.
0164    */
0165   void getFastJets(double rjet, Energy ejcut, double etajcut) const;
0166 
0167   /**
0168    * Find jets using the FastJet package on particlesToCluster_.
0169    */
0170   void getFastJetsToMatch(double rjet) const;
0171 
0172   /**
0173    * Deletes particles from partonsToMatch_ and particlesToCluster_
0174    * vectors so that these contain only the partons to match to the
0175    * jets and the particles used to build jets respectively. By and
0176    * large the candidates for deletion are: vector bosons and their
0177    * decay products, Higgs bosons, photons as well as _primary_, i.e.
0178    * present in the lowest multiplicity process, heavy quarks and
0179    * any related decay products.
0180    */
0181   void caldel_m() const;
0182 
0183     /**
0184    * Deletes particles from partonsToMatch_ and particlesToCluster_
0185    * vectors so that these contain only the partons to match to the
0186    * jets and the particles used to build jets respectively. The candidates 
0187    * are chosen according to the information passed from madgraph. 
0188    */
0189   void caldel_mg() const;
0190 
0191   /**  
0192    * c++ translation of subroutine of same name from alpsho.f.
0193    * Label all particles with status between ISTLO and ISTHI 
0194    * (until a particle with status ISTOP is found) as final-state,
0195    * call calsim_m and then put labels back to normal. This 
0196    * version keeps only all IST=1 particles rejected by caldel as
0197    * daughters of vetoed heavy-quark mothers: jets complementary
0198    * to those reconstructed by caldel.
0199    */
0200   void caldel_hvq() const;
0201 
0202   /**
0203    * get the MG5_aMC information required for FxFx merging
0204    */
0205   void getnpFxFx() const;
0206 
0207   /**
0208    * get the MG5_aMC information required for FxFx merging
0209    */
0210   void getECOM() const;
0211 
0212 
0213   /**
0214    * get the MG5_aMC information required for tree-level merging
0215    */
0216   void getptclust() const;
0217 
0218   /** 
0219    * Erases all occurences of a substring from a string 
0220    */
0221   
0222   void erase_substr(std::string& subject, const std::string& search) const;
0223 
0224 
0225   /**
0226    * Get the particles from lastXCombPtr filling the pair
0227    * preshowerISPs_ and particle pointer vector preshowerFSPs_.
0228    */
0229   void getPreshowerParticles() const;
0230 
0231   /**
0232    * Get the particles from eventHandler()->currentEvent()->...
0233    * filling the particle pairs showeredISHs_, showeredISPs_,
0234    * showeredRems_ and the particle pointer vector showeredFSPs_.
0235    */
0236   void getShoweredParticles() const;
0237 
0238   /**
0239    * Allows printing of debug output and sanity checks like
0240    * total momentum consrvation to be carried out.
0241    * debugLevel = -1, 0, ...5 
0242    *            = no debugging, minimal debugging, ... verbose.
0243    */
0244   void doSanityChecks(int debugLevel) const;
0245 
0246   /**
0247    * Given a pointer to a particle this finds all its final state
0248    * descendents.
0249    */
0250   void getDescendents(PPtr theParticle) const;
0251 
0252   /**
0253    * Accumulates all descendents of tops down to the b and W
0254    * but not including them.
0255    */
0256   void getTopRadiation(PPtr theParticle) const;
0257 
0258   /** 
0259    * Sorts a given vector of particles by descending pT or ETJET
0260    */
0261   
0262   ParticleVector pTsort(ParticleVector unsortedVec);
0263   pair< vector<Energy>, vector<Lorentz5Momentum> > ETsort(vector<Energy> unsortedetjet, vector<Lorentz5Momentum> unsortedVec);
0264 
0265   /* 
0266    * A function that prints a vector of Lorentz5Momenta in a fancy way
0267    */
0268   void printMomVec(vector<Lorentz5Momentum> momVec);
0269 
0270 
0271   /* 
0272    * A probability function for varying etclus_ about the mean value
0273    */
0274   Energy etclusran_(double petc) const;
0275 
0276 private:
0277   
0278   /**
0279    * The static object used to initialize the description of this class.
0280    * Indicates that this is a concrete class with persistent data.
0281    */
0282   static ClassDescription<FxFxHandler> initFxFxHandler;
0283 
0284   /**
0285    * The assignment operator is private and must never be called.
0286    * In fact, it should not even be implemented.
0287    */
0288   FxFxHandler & operator=(const FxFxHandler &) = delete;
0289 
0290 private:
0291 
0292  
0293   /**
0294    *  Initial-state incoming partons prior to showering
0295    *  (i.e. from lastXCombPtr).
0296    */
0297   mutable PPair preshowerISPs_;
0298 
0299   /**
0300    *  Final-state outgoing partICLEs prior to showering
0301    *  (i.e. from lastXCombPtr).
0302    */
0303   mutable ParticleVector preshowerFSPs_;
0304 
0305   /**
0306    *  Final-state outgoing partICLEs prior to showering _to_be_removed_
0307    *  from preShowerFSPs_ prior to the light-parton-light-jet matching
0308    *  step. This same list is the starting point for determining 
0309    *  partonsToMatch_ for the case of merging in heavy quark production.
0310    */
0311   mutable ParticleVector preshowerFSPsToDelete_;
0312 
0313   /**
0314    *  Initial-state incoming hadrons after shower of hard process
0315    *  (eventHandler()->currentEvent()->incoming()).
0316    */
0317   mutable PPair showeredISHs_;
0318 
0319   /**
0320    *  Initial-state incoming partons after shower of hard process
0321    *  (look for partonic children of showeredISHs_).
0322    */
0323   mutable PPair showeredISPs_;
0324 
0325   /**
0326    *  Final-state outgoing partICLEs after shower of hard process
0327    *  (eventHandler()->currentEvent()->getFinalState()).
0328    */
0329   mutable tPVector showeredFSPs_;
0330 
0331   /**
0332    *  Final-state outgoing partICLEs after shower of hard process
0333    *  _to_be_removed_ from showeredFSPs_ prior to the
0334    *  light-parton-light-jet matching step. This same list is the
0335    *  starting point for determining particlesToCluster_ for the
0336    *  case of merging in heavy quark production.
0337    */
0338   mutable ParticleVector showeredFSPsToDelete_;
0339 
0340   /**
0341    *  ONLY the final-state partons from preshowerFSPs_ that are
0342    *  supposed to enter the jet-parton matching.
0343    */
0344   mutable ParticleVector partonsToMatch_;
0345  
0346   /*
0347    * The shower progenitors
0348    */
0349 
0350   mutable PPtr theProgenitor;
0351   mutable PPtr theLastProgenitor;
0352 
0353   /**
0354    *  ONLY the final-state particles from showeredFSPs_ (and maybe
0355    *  also showeredRems_) that are supposed to go for jet clustering.
0356    */
0357   mutable tPVector particlesToCluster_;
0358 
0359   /**
0360    *  Final-state remnants after shower of hard process
0361    *  (look for remnants initially in showeredFSPs_).
0362    */
0363   mutable PPair showeredRems_;
0364 
0365   /**
0366    * the COM of the incoming hadrons
0367    */
0368   
0369   mutable double ECOM_;
0370 
0371   /**
0372    *  Pointer to the object calculating the strong coupling
0373    */
0374   ShowerAlphaPtr alphaS_;
0375 
0376   /**
0377    *  Information extracted from the XComb object
0378    */
0379   //@{
0380   /**
0381    * The fixed factorization scale used in the MEs.
0382    */
0383   Energy pdfScale_;
0384 
0385   /**
0386    *  Centre of mass energy
0387    */
0388   Energy2 sHat_;
0389 
0390   /**
0391    * Constant alphaS used to generate LH events - if not already
0392    * using CKKW scale (ickkw = 1 in AlpGen for example).
0393    */
0394   double alphaSME_;
0395   //@}
0396 
0397   /*
0398    * Number of rapidity segments of the calorimeter.
0399    */
0400   unsigned int ncy_;
0401 
0402   /*
0403    * Number of phi segments of the calorimeter.
0404    */
0405   unsigned int ncphi_;
0406 
0407   /*
0408    * Heavy flavour in WQQ,ZQQ,2Q etc (4=c, 5=b, 6=t).
0409    */
0410   int ihvy_;
0411 
0412   /*
0413    * Number of photons in the AlpGen process.
0414    */
0415   int nph_;
0416 
0417   /*
0418    * Number of higgses in the AlpGen process.
0419    */
0420   int nh_;
0421 
0422   /*
0423    * Jet ET cut to apply in jet clustering (in merging).
0424    */
0425   mutable Energy etclus_;
0426 
0427   
0428 
0429   /*
0430    * The merging mode (FxFx vs tree-level) used. 
0431    */
0432   int mergemode_;
0433 
0434 
0435 
0436   /*
0437    * Allows the vetoing on heavy quark decay products to be turned off. 
0438    */
0439   bool vetoHeavyQ_;
0440 
0441   /* 
0442    * Allows vetoing of heavy flavour 
0443    */
0444 
0445   bool vetoHeavyFlavour_;
0446 
0447 
0448   /*
0449    * Mean Jet ET cut to apply in jet clustering (in merging).
0450    */
0451   Energy etclusmean_;
0452 
0453   
0454   /*
0455    * The jet algorithm used for parton-jet matching in the MLM procedure.
0456    */
0457   int jetAlgorithm_;
0458    
0459   /*
0460    * Allows the vetoing to be turned off completely - just for convenience.
0461    */
0462   bool vetoIsTurnedOff_;
0463 
0464       /* 
0465    * Veto if there exist softer unmatched jets than matched
0466    */
0467 
0468   bool vetoSoftThanMatched_;
0469 
0470     /*
0471    * This flags whether the etclus_ (merging scale) should be fixed or variable according to a prob. distribution around the mean
0472    */
0473   bool etclusfixed_;
0474 
0475 
0476 
0477   /*
0478    * maximum deviation from mean Jet ET cut to apply in jet clustering (in merging).
0479    */
0480   Energy epsetclus_;
0481 
0482 
0483 
0484   /*
0485    * Cone size used in jet clustering (in merging).
0486    */
0487   double rclus_;
0488 
0489   /*
0490    * Max |eta| for jets in clustering (in merging).
0491    */
0492   double etaclmax_;
0493 
0494   /*
0495    * Default 1.5 factor used to decide if a jet matches a parton
0496    * in merging: if DR(parton,jet)<rclusfactor*rclus the parton
0497    * and jet are said to have been matched.
0498    */
0499   double rclusfactor_;
0500 
0501  /*
0502   * Determines whether to detect the hard process or to manually determine which particles 
0503   * to include in the merging. If False, then the ihrd code below is used.
0504   */
0505   bool hpdetect_;
0506   
0507   /*
0508    * The AlpGen hard process code. Relation to the AlpGen process names:
0509    * 1: wqq, 2: zqq, 3: wjet, 4: zjet, 5: vbjet, 6: 2Q, 8: QQh, 9: Njet, 
0510    * 10: wcjet, 11: phjet, 12: hjet, 13: top, 14: wphjet, 15: wphqq, 
0511    * 16: 2Qph.
0512    */
0513   int ihrd_;
0514 
0515   /*
0516    * The number of light jets in the AlpGen process (i.e. the 'extra' ones).
0517    */
0518   int njets_;
0519 
0520   /*
0521    * Mimimum parton-parton R-sep used for generation (used for hvq merging).
0522    */
0523   double drjmin_;
0524 
0525   /*
0526    * This flags that the highest multiplicity ME-level process is
0527    * being processed.
0528    */
0529   mutable bool highestMultiplicity_;
0530 
0531     /*
0532    * The forwards rapidity span of the calorimeter.
0533    */
0534   double ycmax_;
0535 
0536 
0537     /*
0538    * The backwards rapidity span of the calorimeter.
0539    */
0540   double ycmin_;
0541 
0542 
0543 
0544 
0545 
0546 
0547   
0548 
0549 
0550 
0551   
0552 
0553   /*
0554    * Cosine of phi values of calorimeter cell centres.
0555    * Goes phi~=0 to phi~=2*pi          (index = 0 ---> ncphi).
0556    * ==> Cosine goes from +1 ---> +1   (index = 0 ---> ncphi).
0557    */
0558   vector<double> cphcal_;
0559 
0560   /*
0561    * Sine of phi values of calorimeter cell centres.
0562    * Goes phi~=0 to phi~=2*pi             (index = 0 ---> ncphi).
0563    * ==> Sine goes 0 -> 1 -> 0 -> -1 -> 0 (index = 0 ---> ncphi).
0564    */
0565   vector<double> sphcal_;
0566 
0567   /*
0568    * Cosine of theta values of calorimeter cell centres in Y. 
0569    * Goes bwds th~=pi to fwds th~=0       (index = 0 ---> ncy).
0570    * ==> Cosine goes from -1 ---> +1      (index = 0 ---> ncy).
0571    */
0572   vector<double> cthcal_;
0573 
0574   /*
0575    * Sine of theta values of calorimeter cell centres in Y. 
0576    * Goes bwds th~=pi to fwds th~=0       (index = 0 ---> ncy).
0577    * ==> Sine goes from  0 ---> +1 ---> 0 (index = 0 ---> ncy).
0578    */
0579   vector<double> sthcal_;
0580 
0581   /*
0582    * Transverse energy deposit in a given calorimeter cell.
0583    * First array index corresponds to rapidity index of cell,
0584    * second array index corresponds to phi cell index.
0585    */
0586   vector<vector<Energy> > et_;
0587 
0588   /*
0589    * For a given calorimeter cell this holds the index of the jet
0590    * that the cell was clustered into.
0591    */
0592   vector<vector<int> > jetIdx_;
0593 
0594   /*
0595    * Vector holding the Lorentz 5 momenta of each jet.
0596    */
0597   mutable vector<Lorentz5Momentum> pjet_;
0598 
0599   /*
0600    * Vector holding the Lorentz 5 momenta of each jet from ME partons
0601    */
0602   mutable vector<Lorentz5Momentum> pjetME_;
0603 
0604 
0605   /*
0606    * Vector holding the list of FS particles resulting from 
0607    * the particle input to getDescendents.
0608    */
0609   mutable ParticleVector tmpList_;
0610 
0611   /*
0612    * Variables for the C++ translation of the calini_m(), calsim_m(),
0613    * getjet_m(...) and caldel_m() functions 
0614    */
0615   mutable vector<Energy> etjet_;
0616   vector<Energy> etjetME_;
0617   mutable double dely_, delphi_;
0618   
0619 };
0620 
0621 }
0622 
0623 #include "ThePEG/Utilities/ClassTraits.h"
0624 
0625 namespace ThePEG {
0626 
0627 /** @cond TRAITSPECIALIZATIONS */
0628 
0629 /** This template specialization informs ThePEG about the
0630  *  base classes of FxFxHandler. */
0631 template <>
0632 struct BaseClassTrait<Herwig::FxFxHandler,1> {
0633   /** Typedef of the first base class of FxFxHandler. */
0634   typedef Herwig::QTildeShowerHandler NthBase;
0635 };
0636 
0637 /** This template specialization informs ThePEG about the name of
0638  *  the FxFxHandler class and the shared object where it is defined. */
0639 template <>
0640 struct ClassTraits<Herwig::FxFxHandler>
0641   : public ClassTraitsBase<Herwig::FxFxHandler> {
0642   /** Return a platform-independent class name */
0643   static string className() { return "Herwig::FxFxHandler"; }
0644   /**
0645    * The name of a file containing the dynamic library where the class
0646    * FxFxHandler is implemented. It may also include several, space-separated,
0647    * libraries if the class FxFxHandler depends on other classes (base classes
0648    * excepted). In this case the listed libraries will be dynamically
0649    * linked in the order they are specified.
0650    */
0651   static string library() { return "HwFxFxHandler.so"; }
0652 };
0653 
0654 /** @endcond */
0655 
0656 }
0657 
0658 #endif /* HERWIG_FxFxHandler_H */