herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
FxFxReader.h
1 // -*- C++ -*-
2 //
3 // FxFxReader.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef THEPEG_FxFxReader_H
10 #define THEPEG_FxFxReader_H
11 // This is the declaration of the FxFxReader class.
12 
13 #include "FxFx.h"
14 #include "ThePEG/Handlers/HandlerBase.h"
15 #include "ThePEG/Utilities/ObjectIndexer.h"
16 #include "ThePEG/Utilities/Exception.h"
17 #include "ThePEG/Utilities/XSecStat.h"
18 #include "ThePEG/PDF/PartonBinInstance.h"
19 #include "ThePEG/PDF/PartonBin.fh"
20 #include "ThePEG/MatrixElement/ReweightBase.h"
21 #include "FxFxEventHandler.fh"
22 #include "FxFxReader.fh"
23 #include "ThePEG/Utilities/CFile.h"
24 #include <cstdio>
25 #include <cstring>
26 
27 namespace ThePEG {
28 
77 class FxFxReader: public HandlerBase, public LastXCombInfo<> {
78 
82  friend class FxFxEventHandler;
83 
88  typedef map<int,XSecStat> StatMap;
89 
94  typedef map<tcPBPair,XCombPtr> XCombMap;
95 
99  typedef vector<ReweightPtr> ReweightVector;
100 
101 public:
102 
110  FxFxReader(bool active = false);
111 
115  FxFxReader(const FxFxReader &);
116 
120  virtual ~FxFxReader();
122 
123 public:
124 
134  virtual void open() = 0;
135 
141  virtual bool doReadEvent() = 0;
142 
146  virtual void close() = 0;
147 
151  // virtual vector<string> optWeightsNamesFunc();
152  virtual vector<string> optWeightsNamesFunc() = 0;
153  //virtual vector<string*> optWeightNamesFunc() = 0;
154  vector<string> optionalWeightsNames;
155 
160  // vector<string> optionalWeightsNames;
161 
162 
164 
174  virtual void initialize(FxFxEventHandler & eh);
175 
188  virtual double getEvent();
189 
195  virtual bool readEvent();
196 
202  virtual void skip(long n);
203 
211 
217 
224  virtual long scan();
225 
230  virtual void initStat();
231 
237  double reweight();
238 
243  virtual void fillEvent();
244 
249  void reset();
250 
258  virtual void setWeightScale(long neve);
259 
261 
264 
270  static size_t eventSize(int N) {
271  return (N + 1)*sizeof(int) + // IDPRUP, ISTUP
272  (7*N + 4)*sizeof(double) + // XWGTUP, SCALUP, AQEDUP, AQCDUP, PUP,
273  // VTIMUP, SPINUP
274  N*sizeof(long) + // IDUP
275  2*N*sizeof(pair<int,int>) + // MOTHUP, ICOLUP
276  sizeof(pair<double,double>) + // XPDWUP.
277  2*sizeof(double); // lastweight and preweight
278  }
279 
286  double eventWeight() const { return hepeup.XWGTUP*lastweight; }
287 
291  const map<string,double>& optionalEventWeights() const { return optionalWeights; }
292 
296  const int& optionalEventnpLO() const { return optionalnpLO; }
297  const int& optionalEventnpNLO() const { return optionalnpNLO; }
298 
307  const PPair & beams() const { return theBeams; }
312  const PPair & incoming() const { return theIncoming; }
317  const PVector & outgoing() const { return theOutgoing; }
322  const PVector & intermediates() const { return theIntermediates; }
329  int maxMultCKKW() const { return theMaxMultCKKW; }
336  int minMultCKKW() const { return theMinMultCKKW; } //@}
337 
344  long NEvents() const { return theNEvents; }
345 
350  long currentPosition() const { return position; }
351 
357  long maxScan() const { return theMaxScan; }
358 
362  bool active() const { return isActive; }
363 
367  bool negativeWeights() const { return heprup.IDWTUP < 0; }
368 
372  const XSecStat & xSecStats() const { return stats; }
373 
377  const StatMap & processStats() const { return statmap; }
378 
383  void select(double weight) {
384  stats.select(weight);
385  statmap[hepeup.IDPRUP].select(weight);
386  }
387 
391  void accept() {
392  stats.accept();
393  statmap[hepeup.IDPRUP].accept();
394  }
395 
399  void reject(double w) {
400  stats.reject(w);
401  statmap[hepeup.IDPRUP].reject(w);
402  }
403 
407  virtual void increaseMaxXSec(CrossSection maxxsec);
408 
413 
418  tCascHdlPtr CKKWHandler() const { return theCKKW; }
419 
424  const PartonPairVec & partonBins() const { return thePartonBins; }
425 
430  const XCombMap & xCombs() const { return theXCombs; }
431 
435  const Cuts & cuts() const { return *theCuts; }
436 
438 
439 protected:
440 
443 
448  string cacheFileName() const { return theCacheFileName; }
449 
454  bool cutEarly() const { return doCutEarly; }
455 
459  CFile cacheFile() const { return theCacheFile;}
460 
464  void openReadCacheFile();
465 
469  void openWriteCacheFile();
470 
474  void closeCacheFile();
475 
479  void cacheEvent() const;
480 
484  bool uncacheEvent();
485 
491  void reopen();
492 
496  template <typename T>
497  static char * mwrite(char * pos, const T & t, size_t n = 1) {
498  std::memcpy(pos, &t, n*sizeof(T));
499  return pos + n*sizeof(T);
500  }
501 
505  template <typename T>
506  static const char * mread(const char * pos, T & t, size_t n = 1) {
507  std::memcpy(&t, pos, n*sizeof(T));
508  return pos + n*sizeof(T);
509  }
510 
512 
521  virtual bool checkPartonBin();
522 
527  virtual void createParticles();
528 
534  virtual tcPBPair createPartonBinInstances();
535 
541  virtual void createBeams();
542 
546  virtual void connectMothers();
548 
549 public:
550 
557  void persistentOutput(PersistentOStream & os) const;
558 
564  void persistentInput(PersistentIStream & is, int version);
566 
570  static void Init();
571 
572 protected:
573 
580  void NEvents(long x) { theNEvents = x; }
581 
586  XCombMap & xCombs() { return theXCombs; }
588 
596  virtual void doinit();
597 
602  virtual void doinitrun();
603 
608  virtual void dofinish() {
609  close();
611  }
612 
617  virtual bool preInitialize() const;
618 
623  virtual void initPDFs();
625 
626 protected:
627 
632 
637 
642 
648  pair<PDFPtr,PDFPtr> inPDF;
649 
653  pair<cPDFPtr,cPDFPtr> outPDF;
654 
659 
664 
669  PartonPairVec thePartonBins;
670 
675  XCombMap theXCombs;
676 
680  CutsPtr theCuts;
681 
687 
692  long position;
693 
697  int reopened;
698 
705 
709  bool scanning;
710 
714  bool isActive;
715 
721 
727 
732 
736  StatMap statmap;
737 
743 
749 
755 
760 
766 
772 
778 
783 
787  ReweightVector reweights;
788 
792  ReweightVector preweights;
793 
797  double preweight;
798 
803 
809 
817 
825 
831  double lastweight;
832 
836  map<string,double> optionalWeights;
837 
843  double maxFactor;
844 
849 
854 
859  CrossSection weightScale;
860 
864  vector<double> xSecWeights;
865 
870  map<int,double> maxWeights;
871 
875  bool skipping;
876 
880  unsigned int theMomentumTreatment;
881 
887 
892 
897 
898 private:
899 
901  void setBeamA(long id);
903  long getBeamA() const;
905  void setBeamB(long id);
907  long getBeamB() const;
909  void setEBeamA(Energy e);
911  Energy getEBeamA() const;
913  void setEBeamB(Energy e);
915  Energy getEBeamB() const;
917  void setPDFA(PDFPtr);
919  PDFPtr getPDFA() const;
921  void setPDFB(PDFPtr);
923  PDFPtr getPDFB() const;
924 
925 private:
926 
931 
935  FxFxReader & operator=(const FxFxReader &) = delete;
936 
937 public:
938 
942  class FxFxInconsistencyError: public Exception {};
943 
946  class FxFxReopenWarning: public Exception {};
947 
950  class FxFxReopenError: public Exception {};
951 
954  class FxFxInitError: public InitException {};
957 };
958 
960 ostream & operator<<(ostream & os, const HEPEUP & h);
961 
962 }
963 
964 
965 #include "ThePEG/Utilities/ClassTraits.h"
966 
967 namespace ThePEG {
968 
975 template <>
976 struct BaseClassTrait<FxFxReader,1>: public ClassTraitsType {
978  typedef HandlerBase NthBase;
979 };
980 
986 template <>
987 struct ClassTraits<FxFxReader>
988  : public ClassTraitsBase<FxFxReader> {
992  static string className() { return "Herwig::FxFxReader"; }
998  static string library() { return "HwFxFx.so"; }
999 
1000 };
1001 
1004 }
1005 
1006 #endif /* THEPEG_FxFxReader_H */
long theNEvents
The number of events in this reader.
Definition: FxFxReader.h:686
pair< tcPDPtr, tcPDPtr > tcPDPair
static const char * mread(const char *pos, T &t, size_t n=1)
Helper function to read a variable from a memory location.
Definition: FxFxReader.h:506
long maxScan() const
The maximum number of events to scan to collect information about processes and cross sections...
Definition: FxFxReader.h:357
long NEvents() const
The number of events found in this reader.
Definition: FxFxReader.h:344
string theCacheFileName
Name of file used to cache the events form the reader in a fast-readable form.
Definition: FxFxReader.h:720
void select(double weight)
void closeCacheFile()
Close the cache file;.
map< string, double > optionalWeights
The optional weights associated to the last read events.
Definition: FxFxReader.h:836
bool uncacheEvent()
Read an event from the cache file.
bool theReOpenAllowed
Option to allow reopening of the file.
Definition: FxFxReader.h:891
void reopen()
Reopen a reader.
virtual long scan()
Scan the file or stream to obtain information about cross section weights and particles etc...
virtual vector< string > optWeightsNamesFunc()=0
return the weight names
void openReadCacheFile()
Open the cache file for reading.
int minMultCKKW() const
If this reader is to be used (possibly together with others) for CKKW reweighting and veto...
Definition: FxFxReader.h:336
bool active() const
Return true if this reader is active.
Definition: FxFxReader.h:362
long getBeamA() const
Access function for the interface.
The FxFxEventHandler inherits from the general EventHandler class and administers the reading of even...
XSecStat stats
Collect statistics for this reader.
Definition: FxFxReader.h:731
tCascHdlPtr theCKKW
A pointer to a CascadeHandler to be used for CKKW-reweighting.
Definition: FxFxReader.h:663
void setBeamA(long id)
Access function for the interface.
pair< cPDFPtr, cPDFPtr > outPDF
The PDFBase object to be used in the subsequent generation.
Definition: FxFxReader.h:653
virtual void close()=0
Close the file or stream from which events have been read.
int optionalnpLO
npLO for FxFx merging
Definition: FxFxReader.h:848
virtual void connectMothers()
Go through the mother indices and connect up the Particles.
tCascHdlPtr CKKWHandler() const
Return a possibly null pointer to a CascadeHandler to be used for CKKW-reweighting.
Definition: FxFxReader.h:418
const XCombMap & xCombs() const
The map of XComb objects indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:430
PExtrPtr thePartonExtractor
The PartonExtractor object used to construct remnants.
Definition: FxFxReader.h:658
void accept()
Accept the current event assuming it was previously selcted.
Definition: FxFxReader.h:391
void setPDFA(PDFPtr)
Access function for the interface.
bool useWeightWarnings
Set to true if warnings about possible weight incompatibilities should be issued. ...
Definition: FxFxReader.h:886
virtual bool doReadEvent()=0
Read the next event from the file or stream into the corresponding protected variables.
bool theIncludeSpin
Use the spin information.
Definition: FxFxReader.h:896
virtual bool checkPartonBin()
Check the existence of a pair of PartonBin objects corresponding to the current event.
map< int, double > maxWeights
Individual maximum weights for individual (possibly reweighted) processes.
Definition: FxFxReader.h:870
ObjectIndexer< long, ColourLine > colourIndex
Association between ColourLines and colour indices in the current translation.
Definition: FxFxReader.h:748
double preweight
The factor with which this reader was last pre-weighted.
Definition: FxFxReader.h:797
bool doInitPDFs
Should PDFBase objects be constructed from the information in the event file in the initialization...
Definition: FxFxReader.h:808
bool scanning
Flag to tell whether we are in the process of scanning.
Definition: FxFxReader.h:709
int IDWTUP
Master switch indicating how the ME generator envisages the events weights should be interpreted acco...
Definition: FxFx.h:89
PBIPair thePartonBinInstances
The pair of PartonBinInstance objects describing the current incoming partons in the event...
Definition: FxFxReader.h:742
pair< PDFPtr, PDFPtr > inPDF
The PDFBase objects which has been used for the beam particle when generating the events being read...
Definition: FxFxReader.h:648
bool skipping
Is set to true when getEvent() is called from skip(int).
Definition: FxFxReader.h:875
int optionalnpNLO
npNLO for FxFx merging
Definition: FxFxReader.h:853
void openWriteCacheFile()
Open the cache file for writing.
void cacheEvent() const
Write the current event to the cache file.
long currentPosition() const
The number of events produced so far.
Definition: FxFxReader.h:350
double eventWeight() const
The current event weight given by XWGTUP times possible reweighting.
Definition: FxFxReader.h:286
FxFxReader is an abstract base class to be used for objects which reads event files or streams from m...
Definition: FxFxReader.h:77
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
StatMap statmap
Collect statistics for each individual process.
Definition: FxFxReader.h:736
void reject(double weight=1.0)
CFile theCacheFile
File stream for the cache.
Definition: FxFxReader.h:782
map< int, XSecStat > StatMap
Map for accumulating statistics of cross sections per process number.
Definition: FxFxReader.h:88
virtual void increaseMaxXSec(CrossSection maxxsec)
Increase the overestimated cross section for this reader.
void setEBeamB(Energy e)
Access function for the interface.
vector< double > xSecWeights
Individual scales for different sub-processes if reweighted.
Definition: FxFxReader.h:864
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
virtual void skip(long n)
Skip n events.
int reopened
The number of times this reader has been reopened.
Definition: FxFxReader.h:697
void reject(double w)
Reject the current event assuming it was previously accepted.
Definition: FxFxReader.h:399
HEPEUP hepeup
The HEPEUP common block.
Definition: FxFxReader.h:636
static size_t eventSize(int N)
Return the size of this event in bytes.
Definition: FxFxReader.h:270
CutsPtr theCuts
The Cuts object to be used for this reader.
Definition: FxFxReader.h:680
long theMaxScan
The maximum number of events to scan to collect information about processes and cross sections...
Definition: FxFxReader.h:704
HEPRUP heprup
The HEPRUP common block.
Definition: FxFxReader.h:631
const XSecStat & xSecStats() const
The collected cross section statistics for this reader.
Definition: FxFxReader.h:372
double lastweight
The weight multiplying the last read event due to PDF reweighting, CKKW reweighting or assigned rewei...
Definition: FxFxReader.h:831
ReweightVector preweights
The preweight objects modifying the weights of this reader.
Definition: FxFxReader.h:792
const Cuts & cuts() const
The Cuts object to be used for this reader.
Definition: FxFxReader.h:435
ReweightVector reweights
The reweight objects modifying the weights of this reader.
Definition: FxFxReader.h:787
static void Init()
Standard Init function used to initialize the interfaces.
virtual void fillEvent()
Converts the information in the Les Houches common block variables into a Particle objects...
PDFPtr getPDFB() const
Access function for the interface.
const PVector & intermediates() const
Return the instances of the intermediate particles in the sub process for the current event...
Definition: FxFxReader.h:322
virtual void initPDFs()
Called from doinit() to extract PDFs from the event file and add the corresponding objects to the cur...
ThePEG::Ptr< CascadeHandler >::transient_pointer tCascHdlPtr
virtual double getEvent()
Calls readEvent() or uncacheEvent() to read information into the FxFx common block variables...
tXCombPtr getXComb()
Get an XComb object.
void select(double weight)
Select the current event.
Definition: FxFxReader.h:383
void reset()
Removes the particles created in the last generated event, preparing to produce a new one...
virtual void doinitrun()
Initialize this object.
map< tcPBPair, XCombPtr > XCombMap
Map of XComb objects describing the incoming partons indexed by the corresponding PartonBin pair...
Definition: FxFxReader.h:94
XCombMap theXCombs
The map of XComb objects indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:675
const map< string, double > & optionalEventWeights() const
Return the optional named weights associated to the current event.
Definition: FxFxReader.h:291
bool cutEarly() const
Determines whether to apply cuts to events converting them to ThePEG format.
Definition: FxFxReader.h:454
FxFxReader & operator=(const FxFxReader &)=delete
Private and non-existent assignment operator.
void setEBeamA(Energy e)
Access function for the interface.
virtual void open()=0
Open a file or stream with events and read in the run information into the heprup variable...
int theMaxMultCKKW
If this reader is to be used (possibly together with others) for CKKW reweighting and veto...
Definition: FxFxReader.h:816
static AbstractClassDescription< FxFxReader > initFxFxReader
Describe an abstract base class with persistent data.
Definition: FxFxReader.h:930
ThePEG::Ptr< SubProcess >::transient_pointer tSubProPtr
pair< PPtr, PPtr > PPair
pair< PBIPtr, PBIPtr > PBIPair
PartonPairVec thePartonBins
The pairs of PartonBin objects describing the partons which can be extracted by the PartonExtractor o...
Definition: FxFxReader.h:669
Energy getEBeamA() const
Access function for the interface.
PVector theIntermediates
The instances of the intermediate particles in the sub process for the current event.
Definition: FxFxReader.h:777
const PartonPairVec & partonBins() const
The pairs of PartonBin objects describing the partons which can be extracted by the PartonExtractor o...
Definition: FxFxReader.h:424
virtual void dofinish()
bool isActive
True if this is an active reader.
Definition: FxFxReader.h:714
long position
The number of events produced by this reader so far.
Definition: FxFxReader.h:692
bool negativeWeights() const
True if negative weights may be produced.
Definition: FxFxReader.h:367
bool doCutEarly
Determines whether to apply cuts to events before converting them to ThePEG format.
Definition: FxFxReader.h:726
vector< ReweightPtr > ReweightVector
A vector of pointers to ReweightBase objects.
Definition: FxFxReader.h:99
const PBIPair & partonBinInstances() const
The pair of PartonBinInstance objects describing the current incoming partons in the event...
Definition: FxFxReader.h:303
PPair theIncoming
The instances of the incoming particles to the sub process for the current event. ...
Definition: FxFxReader.h:765
unsigned int theMomentumTreatment
Option for the treatment of the momenta supplied.
Definition: FxFxReader.h:880
const PPair & beams() const
Return the instances of the beam particles for the current event.
Definition: FxFxReader.h:307
void setBeamB(long id)
Access function for the interface.
PDFPtr getPDFA() const
Access function for the interface.
long getBeamB() const
Access function for the interface.
PPair theBeams
The instances of the beam particles for the current event.
Definition: FxFxReader.h:759
virtual void dofinish()
Finalize this object.
Definition: FxFxReader.h:608
string cacheFileName() const
Name of file used to cache the events form the reader in a fast-readable form.
Definition: FxFxReader.h:448
tSubProPtr getSubProcess()
Get a SubProcess object corresponding to the information in the Les Houches common block variables...
const int & optionalEventnpLO() const
Return the optional npLO and npNLO.
Definition: FxFxReader.h:296
The HEPEUP class is a simple container corresponding to the Les Houches accord (hep-ph/0109068) commo...
Definition: FxFx.h:128
int IDPRUP
The subprocess code for this event (as given in LPRUP).
Definition: FxFx.h:177
static char * mwrite(char *pos, const T &t, size_t n=1)
Helper function to write a variable to a memory location.
Definition: FxFxReader.h:497
The HEPRUP class is a simple container corresponding to the Les Houches accord (hep-ph/0109068) commo...
Definition: FxFx.h:26
Energy getEBeamB() const
Access function for the interface.
virtual bool preInitialize() const
Return true if this object needs to be initialized before all other objects because it needs to extra...
virtual void createBeams()
Create instances of the incoming beams in the event and store them in particleIndex.
virtual bool readEvent()
Calls doReadEvent() and performs pre-defined reweightings.
int theMinMultCKKW
If this reader is to be used (possibly together with others) for CKKW reweighting and veto...
Definition: FxFxReader.h:824
ThePEG::Ptr< PDFBase >::pointer PDFPtr
const PPair & incoming() const
Return the instances of the incoming particles to the sub process for the current event...
Definition: FxFxReader.h:312
vector< T > & operator<<(vector< T > &tv, const U &u)
ObjectIndexer< long, Particle > particleIndex
Association between Particles and indices in the current translation.
Definition: FxFxReader.h:754
FxFxReader(bool active=false)
Default constructor.
XCombMap & xCombs()
The map of XComb objects indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:586
void setPDFB(PDFPtr)
Access function for the interface.
PVector theOutgoing
The instances of the outgoing particles from the sub process for the current event.
Definition: FxFxReader.h:771
virtual ~FxFxReader()
Destructor.
virtual tcPBPair createPartonBinInstances()
Using the already created particles create a pair of PartonBinInstance objects corresponding to the i...
const PVector & outgoing() const
Return the instances of the outgoing particles from the sub process for the current event...
Definition: FxFxReader.h:317
const StatMap & processStats() const
Collected statistics about the individual processes.
Definition: FxFxReader.h:377
ThePEG::Ptr< PartonExtractor >::pointer PExtrPtr
tPExtrPtr partonExtractor() const
The PartonExtractor object used to construct remnants.
Definition: FxFxReader.h:412
virtual void createParticles()
Create instances of all particles in the event and store them in particleIndex.
vector< PPtr > PVector
CrossSection weightScale
The (reweighted) XWGTUP value should be scaled with this cross section when compared to the overestim...
Definition: FxFxReader.h:859
double XWGTUP
The weight for this event.
Definition: FxFx.h:182
int maxMultCKKW() const
If this reader is to be used (possibly together with others) for CKKW reweighting and veto...
Definition: FxFxReader.h:329
virtual void initialize(FxFxEventHandler &eh)
Initialize.
ThePEG::Ptr< XComb >::transient_pointer tXCombPtr
virtual void setWeightScale(long neve)
Possibility for subclasses to recover from non-conformant settings of XMAXUP when an event file has b...
CFile cacheFile() const
File stream for the cache.
Definition: FxFxReader.h:459
bool reweightPDF
Should the event be reweighted by PDFs used by the PartonExtractor?
Definition: FxFxReader.h:802
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
tcPDPair inData
The ParticleData objects corresponding to the incoming particles.
Definition: FxFxReader.h:641
double maxFactor
If the maximum cross section of this reader has been increased with increaseMaxXSec(), this is the total factor with which it has been increased.
Definition: FxFxReader.h:843
virtual void initStat()
Take the information corresponding to the HEPRUP common block and initialize the statistics for this ...
ThePEG::Ptr< PartonExtractor >::transient_pointer tPExtrPtr
double reweight()
Reweights the current event using the reweights and preweights vectors.
void NEvents(long x)
The number of events in this reader.
Definition: FxFxReader.h:580