herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
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
27namespace ThePEG {
28
77class 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
101public:
102
110 FxFxReader(bool active = false);
111
116
120 virtual ~FxFxReader();
122
123public:
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 long& LHEEventNum() const { return LHEeventnum; }
297
301 const int& optionalEventnpLO() const { return optionalnpLO; }
302 const int& optionalEventnpNLO() const { return optionalnpNLO; }
303
312 const PPair & beams() const { return theBeams; }
317 const PPair & incoming() const { return theIncoming; }
322 const PVector & outgoing() const { return theOutgoing; }
327 const PVector & intermediates() const { return theIntermediates; }
334 int maxMultCKKW() const { return theMaxMultCKKW; }
341 int minMultCKKW() const { return theMinMultCKKW; } //@}
342
349 long NEvents() const { return theNEvents; }
350
355 long currentPosition() const { return position; }
356
362 long maxScan() const { return theMaxScan; }
363
367 bool active() const { return isActive; }
368
372 bool negativeWeights() const { return heprup.IDWTUP < 0; }
373
377 const XSecStat & xSecStats() const { return stats; }
378
382 const StatMap & processStats() const { return statmap; }
383
388 void select(double weight) {
389 stats.select(weight);
390 statmap[hepeup.IDPRUP].select(weight);
391 }
392
396 void accept() {
397 stats.accept();
398 statmap[hepeup.IDPRUP].accept();
399 }
400
404 void reject(double w) {
405 stats.reject(w);
406 statmap[hepeup.IDPRUP].reject(w);
407 }
408
412 virtual void increaseMaxXSec(CrossSection maxxsec);
413
418
423 tCascHdlPtr CKKWHandler() const { return theCKKW; }
424
429 const PartonPairVec & partonBins() const { return thePartonBins; }
430
435 const XCombMap & xCombs() const { return theXCombs; }
436
440 const Cuts & cuts() const { return *theCuts; }
441
443
444protected:
445
448
453 string cacheFileName() const { return theCacheFileName; }
454
459 bool cutEarly() const { return doCutEarly; }
460
464 CFile cacheFile() const { return theCacheFile;}
465
470
475
480
484 void cacheEvent() const;
485
490
496 void reopen();
497
501 template <typename T>
502 static char * mwrite(char * pos, const T & t, size_t n = 1) {
503 std::memcpy(pos, &t, n*sizeof(T));
504 return pos + n*sizeof(T);
505 }
506
510 template <typename T>
511 static const char * mread(const char * pos, T & t, size_t n = 1) {
512 std::memcpy(&t, pos, n*sizeof(T));
513 return pos + n*sizeof(T);
514 }
515
517
526 virtual bool checkPartonBin();
527
532 virtual void createParticles();
533
539 virtual tcPBPair createPartonBinInstances();
540
546 virtual void createBeams();
547
551 virtual void connectMothers();
553
554public:
555
563
569 void persistentInput(PersistentIStream & is, int version);
571
575 static void Init();
576
577protected:
578
585 void NEvents(long x) { theNEvents = x; }
586
591 XCombMap & xCombs() { return theXCombs; }
593
601 virtual void doinit();
602
607 virtual void doinitrun();
608
613 virtual void dofinish() {
614 close();
616 }
617
622 virtual bool preInitialize() const;
623
628 virtual void initPDFs();
630
631protected:
632
637
642
647
653 pair<PDFPtr,PDFPtr> inPDF;
654
658 pair<cPDFPtr,cPDFPtr> outPDF;
659
664
669
674 PartonPairVec thePartonBins;
675
681
685 CutsPtr theCuts;
686
692
698
703
710
715
720
726
732
737
742
748
754
760
765
771
777
783
788
793
798
802 double preweight;
803
808
814
822
830
837
841 map<string,double> optionalWeights;
842
847
853 double maxFactor;
854
859
864
869 CrossSection weightScale;
870
874 vector<double> xSecWeights;
875
880 map<int,double> maxWeights;
881
886
891
897
902
907
908private:
909
911 void setBeamA(long id);
913 long getBeamA() const;
915 void setBeamB(long id);
917 long getBeamB() const;
919 void setEBeamA(Energy e);
921 Energy getEBeamA() const;
923 void setEBeamB(Energy e);
925 Energy getEBeamB() const;
934
935private:
936
941
945 FxFxReader & operator=(const FxFxReader &) = delete;
946
947public:
948
952 class FxFxInconsistencyError: public Exception {};
953
956 class FxFxReopenWarning: public Exception {};
957
960 class FxFxReopenError: public Exception {};
961
964 class FxFxInitError: public InitException {};
967};
968
970ostream & operator<<(ostream & os, const HEPEUP & h);
971
972}
973
974
975#include "ThePEG/Utilities/ClassTraits.h"
976
977namespace ThePEG {
978
985template <>
986struct BaseClassTrait<FxFxReader,1>: public ClassTraitsType {
988 typedef HandlerBase NthBase;
989};
990
996template <>
997struct ClassTraits<FxFxReader>
998 : public ClassTraitsBase<FxFxReader> {
1002 static string className() { return "Herwig::FxFxReader"; }
1008 static string library() { return "HwFxFx.so"; }
1009
1010};
1011
1014}
1015
1016#endif /* THEPEG_FxFxReader_H */
The FxFxEventHandler inherits from the general EventHandler class and administers the reading of even...
FxFxReader is an abstract base class to be used for objects which reads event files or streams from m...
Definition: FxFxReader.h:77
const int & optionalEventnpLO() const
Return the optional npLO and npNLO.
Definition: FxFxReader.h:301
virtual ~FxFxReader()
Destructor.
virtual void setWeightScale(long neve)
Possibility for subclasses to recover from non-conformant settings of XMAXUP when an event file has b...
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
tCascHdlPtr CKKWHandler() const
Return a possibly null pointer to a CascadeHandler to be used for CKKW-reweighting.
Definition: FxFxReader.h:423
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
HEPRUP heprup
The HEPRUP common block.
Definition: FxFxReader.h:636
CutsPtr theCuts
The Cuts object to be used for this reader.
Definition: FxFxReader.h:685
bool doCutEarly
Determines whether to apply cuts to events before converting them to ThePEG format.
Definition: FxFxReader.h:731
long theNEvents
The number of events in this reader.
Definition: FxFxReader.h:691
void NEvents(long x)
The number of events in this reader.
Definition: FxFxReader.h:585
void reset()
Removes the particles created in the last generated event, preparing to produce a new one.
map< string, double > optionalWeights
The optional weights associated to the last read events.
Definition: FxFxReader.h:841
virtual vector< string > optWeightsNamesFunc()=0
return the weight names
void reopen()
Reopen a reader.
void setPDFA(PDFPtr)
Access function for the interface.
long getBeamB() const
Access function for the interface.
const XCombMap & xCombs() const
The map of XComb objects indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:435
double lastweight
The weight multiplying the last read event due to PDF reweighting, CKKW reweighting or assigned rewei...
Definition: FxFxReader.h:836
PVector theOutgoing
The instances of the outgoing particles from the sub process for the current event.
Definition: FxFxReader.h:776
ReweightVector preweights
The preweight objects modifying the weights of this reader.
Definition: FxFxReader.h:797
const PVector & outgoing() const
Return the instances of the outgoing particles from the sub process for the current event.
Definition: FxFxReader.h:322
CFile cacheFile() const
File stream for the cache.
Definition: FxFxReader.h:464
const PartonPairVec & partonBins() const
The pairs of PartonBin objects describing the partons which can be extracted by the PartonExtractor o...
Definition: FxFxReader.h:429
PVector theIntermediates
The instances of the intermediate particles in the sub process for the current event.
Definition: FxFxReader.h:782
void setBeamA(long id)
Access function for the interface.
pair< PDFPtr, PDFPtr > inPDF
The PDFBase objects which has been used for the beam particle when generating the events being read.
Definition: FxFxReader.h:653
void reject(double w)
Reject the current event assuming it was previously accepted.
Definition: FxFxReader.h:404
const PVector & intermediates() const
Return the instances of the intermediate particles in the sub process for the current event.
Definition: FxFxReader.h:327
unsigned int theMomentumTreatment
Option for the treatment of the momenta supplied.
Definition: FxFxReader.h:890
const PBIPair & partonBinInstances() const
The pair of PartonBinInstance objects describing the current incoming partons in the event.
Definition: FxFxReader.h:308
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:511
virtual void close()=0
Close the file or stream from which events have been read.
int optionalnpNLO
npNLO for FxFx merging
Definition: FxFxReader.h:863
int theMinMultCKKW
If this reader is to be used (possibly together with others) for CKKW reweighting and veto,...
Definition: FxFxReader.h:829
bool negativeWeights() const
True if negative weights may be produced.
Definition: FxFxReader.h:372
PPair theBeams
The instances of the beam particles for the current event.
Definition: FxFxReader.h:764
void setEBeamB(Energy e)
Access function for the interface.
virtual void dofinish()
Finalize this object.
Definition: FxFxReader.h:613
PDFPtr getPDFA() const
Access function for the interface.
map< int, double > maxWeights
Individual maximum weights for individual (possibly reweighted) processes.
Definition: FxFxReader.h:880
vector< double > xSecWeights
Individual scales for different sub-processes if reweighted.
Definition: FxFxReader.h:874
int maxMultCKKW() const
If this reader is to be used (possibly together with others) for CKKW reweighting and veto,...
Definition: FxFxReader.h:334
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:502
const map< string, double > & optionalEventWeights() const
Return the optional named weights associated to the current event.
Definition: FxFxReader.h:291
const StatMap & processStats() const
Collected statistics about the individual processes.
Definition: FxFxReader.h:382
bool reweightPDF
Should the event be reweighted by PDFs used by the PartonExtractor?
Definition: FxFxReader.h:807
long getBeamA() const
Access function for the interface.
bool isActive
True if this is an active reader.
Definition: FxFxReader.h:719
long LHEeventnum
The event number.
Definition: FxFxReader.h:846
double maxFactor
If the maximum cross section of this reader has been increased with increaseMaxXSec(),...
Definition: FxFxReader.h:853
double reweight()
Reweights the current event using the reweights and preweights vectors.
void accept()
Accept the current event assuming it was previously selcted.
Definition: FxFxReader.h:396
virtual bool preInitialize() const
Return true if this object needs to be initialized before all other objects because it needs to extra...
bool doInitPDFs
Should PDFBase objects be constructed from the information in the event file in the initialization?
Definition: FxFxReader.h:813
virtual double getEvent()
Calls readEvent() or uncacheEvent() to read information into the FxFx common block variables.
void cacheEvent() const
Write the current event to the cache file.
CrossSection weightScale
The (reweighted) XWGTUP value should be scaled with this cross section when compared to the overestim...
Definition: FxFxReader.h:869
virtual void initialize(FxFxEventHandler &eh)
Initialize.
vector< ReweightPtr > ReweightVector
A vector of pointers to ReweightBase objects.
Definition: FxFxReader.h:99
pair< cPDFPtr, cPDFPtr > outPDF
The PDFBase object to be used in the subsequent generation.
Definition: FxFxReader.h:658
tCascHdlPtr theCKKW
A pointer to a CascadeHandler to be used for CKKW-reweighting.
Definition: FxFxReader.h:668
const PPair & incoming() const
Return the instances of the incoming particles to the sub process for the current event.
Definition: FxFxReader.h:317
PExtrPtr thePartonExtractor
The PartonExtractor object used to construct remnants.
Definition: FxFxReader.h:663
double eventWeight() const
The current event weight given by XWGTUP times possible reweighting.
Definition: FxFxReader.h:286
long currentPosition() const
The number of events produced so far.
Definition: FxFxReader.h:355
map< int, XSecStat > StatMap
Map for accumulating statistics of cross sections per process number.
Definition: FxFxReader.h:88
CFile theCacheFile
File stream for the cache.
Definition: FxFxReader.h:787
XSecStat stats
Collect statistics for this reader.
Definition: FxFxReader.h:736
PDFPtr getPDFB() const
Access function for the interface.
const long & LHEEventNum() const
Return the Les Houches event number associated with the current event.
Definition: FxFxReader.h:296
bool skipping
Is set to true when getEvent() is called from skip(int).
Definition: FxFxReader.h:885
const PPair & beams() const
Return the instances of the beam particles for the current event.
Definition: FxFxReader.h:312
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
PPair theIncoming
The instances of the incoming particles to the sub process for the current event.
Definition: FxFxReader.h:770
long position
The number of events produced by this reader so far.
Definition: FxFxReader.h:697
FxFxReader & operator=(const FxFxReader &)=delete
Private and non-existent assignment operator.
map< tcPBPair, XCombPtr > XCombMap
Map of XComb objects describing the incoming partons indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:94
virtual void doinitrun()
Initialize this object.
Energy getEBeamA() const
Access function for the interface.
void openReadCacheFile()
Open the cache file for reading.
bool uncacheEvent()
Read an event from the cache file.
tcPDPair inData
The ParticleData objects corresponding to the incoming particles.
Definition: FxFxReader.h:646
FxFxReader(const FxFxReader &)
Copy-constructor.
ObjectIndexer< long, Particle > particleIndex
Association between Particles and indices in the current translation.
Definition: FxFxReader.h:759
virtual void initPDFs()
Called from doinit() to extract PDFs from the event file and add the corresponding objects to the cur...
tPExtrPtr partonExtractor() const
The PartonExtractor object used to construct remnants.
Definition: FxFxReader.h:417
StatMap statmap
Collect statistics for each individual process.
Definition: FxFxReader.h:741
virtual void open()=0
Open a file or stream with events and read in the run information into the heprup variable.
string theCacheFileName
Name of file used to cache the events form the reader in a fast-readable form.
Definition: FxFxReader.h:725
PartonPairVec thePartonBins
The pairs of PartonBin objects describing the partons which can be extracted by the PartonExtractor o...
Definition: FxFxReader.h:674
static AbstractClassDescription< FxFxReader > initFxFxReader
Describe an abstract base class with persistent data.
Definition: FxFxReader.h:940
static void Init()
Standard Init function used to initialize the interfaces.
long NEvents() const
The number of events found in this reader.
Definition: FxFxReader.h:349
virtual void createParticles()
Create instances of all particles in the event and store them in particleIndex.
long theMaxScan
The maximum number of events to scan to collect information about processes and cross sections.
Definition: FxFxReader.h:709
HEPEUP hepeup
The HEPEUP common block.
Definition: FxFxReader.h:641
virtual tcPBPair createPartonBinInstances()
Using the already created particles create a pair of PartonBinInstance objects corresponding to the i...
void setEBeamA(Energy e)
Access function for the interface.
int theMaxMultCKKW
If this reader is to be used (possibly together with others) for CKKW reweighting and veto,...
Definition: FxFxReader.h:821
ObjectIndexer< long, ColourLine > colourIndex
Association between ColourLines and colour indices in the current translation.
Definition: FxFxReader.h:753
string cacheFileName() const
Name of file used to cache the events form the reader in a fast-readable form.
Definition: FxFxReader.h:453
bool theIncludeSpin
Use the spin information.
Definition: FxFxReader.h:906
PBIPair thePartonBinInstances
The pair of PartonBinInstance objects describing the current incoming partons in the event.
Definition: FxFxReader.h:747
int minMultCKKW() const
If this reader is to be used (possibly together with others) for CKKW reweighting and veto,...
Definition: FxFxReader.h:341
bool useWeightWarnings
Set to true if warnings about possible weight incompatibilities should be issued.
Definition: FxFxReader.h:896
virtual void increaseMaxXSec(CrossSection maxxsec)
Increase the overestimated cross section for this reader.
static size_t eventSize(int N)
Return the size of this event in bytes.
Definition: FxFxReader.h:270
const Cuts & cuts() const
The Cuts object to be used for this reader.
Definition: FxFxReader.h:440
int optionalnpLO
npLO for FxFx merging
Definition: FxFxReader.h:858
const XSecStat & xSecStats() const
The collected cross section statistics for this reader.
Definition: FxFxReader.h:377
double preweight
The factor with which this reader was last pre-weighted.
Definition: FxFxReader.h:802
bool scanning
Flag to tell whether we are in the process of scanning.
Definition: FxFxReader.h:714
Energy getEBeamB() const
Access function for the interface.
bool cutEarly() const
Determines whether to apply cuts to events converting them to ThePEG format.
Definition: FxFxReader.h:459
long maxScan() const
The maximum number of events to scan to collect information about processes and cross sections.
Definition: FxFxReader.h:362
virtual void fillEvent()
Converts the information in the Les Houches common block variables into a Particle objects.
void openWriteCacheFile()
Open the cache file for writing.
void closeCacheFile()
Close the cache file;.
virtual void createBeams()
Create instances of the incoming beams in the event and store them in particleIndex.
void setBeamB(long id)
Access function for the interface.
virtual void initStat()
Take the information corresponding to the HEPRUP common block and initialize the statistics for this ...
virtual void skip(long n)
Skip n events.
virtual bool doReadEvent()=0
Read the next event from the file or stream into the corresponding protected variables.
bool theReOpenAllowed
Option to allow reopening of the file.
Definition: FxFxReader.h:901
virtual void connectMothers()
Go through the mother indices and connect up the Particles.
ReweightVector reweights
The reweight objects modifying the weights of this reader.
Definition: FxFxReader.h:792
FxFxReader(bool active=false)
Default constructor.
virtual bool checkPartonBin()
Check the existence of a pair of PartonBin objects corresponding to the current event.
virtual long scan()
Scan the file or stream to obtain information about cross section weights and particles etc.
int reopened
The number of times this reader has been reopened.
Definition: FxFxReader.h:702
bool active() const
Return true if this reader is active.
Definition: FxFxReader.h:367
virtual bool readEvent()
Calls doReadEvent() and performs pre-defined reweightings.
XCombMap & xCombs()
The map of XComb objects indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:591
tXCombPtr getXComb()
Get an XComb object.
void setPDFB(PDFPtr)
Access function for the interface.
tSubProPtr getSubProcess()
Get a SubProcess object corresponding to the information in the Les Houches common block variables.
XCombMap theXCombs
The map of XComb objects indexed by the corresponding PartonBin pair.
Definition: FxFxReader.h:680
void select(double weight)
Select the current event.
Definition: FxFxReader.h:388
int IDPRUP
Definition: FxFx.h:177
double XWGTUP
Definition: FxFx.h:182
int IDWTUP
Definition: FxFx.h:89
virtual void dofinish()
void select(double weight)
void reject(double weight=1.0)
pair< PPtr, PPtr > PPair
ThePEG::Ptr< PartonExtractor >::transient_pointer tPExtrPtr
pair< PBIPtr, PBIPtr > PBIPair
ThePEG::Ptr< SubProcess >::transient_pointer tSubProPtr
pair< tcPDPtr, tcPDPtr > tcPDPair
ThePEG::Ptr< CascadeHandler >::transient_pointer tCascHdlPtr
vector< PPtr > PVector
ThePEG::Ptr< XComb >::transient_pointer tXCombPtr
ostream & operator<<(ostream &, const Collision &)
ThePEG::Ptr< PDFBase >::pointer PDFPtr
ThePEG::Ptr< PartonExtractor >::pointer PExtrPtr
static string className()
static string library()