00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef THEPEG_LesHouchesReader_H
00010 #define THEPEG_LesHouchesReader_H
00011
00012
00013 #include "LesHouches.h"
00014 #include "ThePEG/Handlers/HandlerBase.h"
00015 #include "ThePEG/Utilities/ObjectIndexer.h"
00016 #include "ThePEG/Utilities/Exception.h"
00017 #include "ThePEG/Utilities/XSecStat.h"
00018 #include "ThePEG/PDF/PartonBinInstance.h"
00019 #include "ThePEG/PDF/PartonBin.fh"
00020 #include "ThePEG/MatrixElement/ReweightBase.h"
00021 #include "LesHouchesEventHandler.fh"
00022 #include "LesHouchesReader.fh"
00023 #include <cstdio>
00024 #include <cstring>
00025
00026 namespace ThePEG {
00027
00076 class LesHouchesReader: public HandlerBase, public LastXCombInfo<> {
00077
00081 friend class LesHouchesEventHandler;
00082
00086 typedef FILE * CFile;
00087
00092 typedef map<int,XSecStat> StatMap;
00093
00098 typedef map<tcPBPair,XCombPtr> XCombMap;
00099
00103 typedef vector<ReweightPtr> ReweightVector;
00104
00105 public:
00106
00114 LesHouchesReader(bool active = false);
00115
00119 LesHouchesReader(const LesHouchesReader &);
00120
00124 virtual ~LesHouchesReader();
00126
00127 public:
00128
00138 virtual void open() = 0;
00139
00145 virtual bool doReadEvent() = 0;
00146
00150 virtual void close() = 0;
00152
00162 virtual void initialize(LesHouchesEventHandler & eh);
00163
00176 virtual double getEvent();
00177
00183 virtual bool readEvent();
00184
00190 virtual void skip(long n);
00191
00198 tXCombPtr getXComb();
00199
00204 tSubProPtr getSubProcess();
00205
00212 virtual long scan();
00213
00218 virtual void initStat();
00219
00225 double reweight();
00226
00231 virtual void fillEvent();
00232
00237 void reset();
00238
00246 virtual void setWeightScale(long neve);
00247
00249
00252
00258 static size_t eventSize(int N) {
00259 return (N + 1)*sizeof(int) +
00260 (7*N + 4)*sizeof(double) +
00261
00262 N*sizeof(long) +
00263 2*N*sizeof(pair<int,int>) +
00264 sizeof(pair<double,double>) +
00265 2*sizeof(double);
00266 }
00267
00274 double eventWeight() const { return hepeup.XWGTUP*lastweight; }
00275
00280 const PBIPair & partonBinInstances() const { return thePartonBinInstances; }
00284 const PPair & beams() const { return theBeams; }
00289 const PPair & incoming() const { return theIncoming; }
00294 const PVector & outgoing() const { return theOutgoing; }
00299 const PVector & intermediates() const { return theIntermediates; }
00306 int maxMultCKKW() const { return theMaxMultCKKW; }
00313 int minMultCKKW() const { return theMinMultCKKW; }
00314
00321 long NEvents() const { return theNEvents; }
00322
00327 long currentPosition() const { return position; }
00328
00334 long maxScan() const { return theMaxScan; }
00335
00339 bool active() const { return isActive; }
00340
00344 bool negativeWeights() const { return heprup.IDWTUP < 0; }
00345
00349 const XSecStat & xSecStats() const { return stats; }
00350
00354 const StatMap & processStats() const { return statmap; }
00355
00360 void select(double weight) {
00361 stats.select(weight);
00362 statmap[hepeup.IDPRUP].select(weight);
00363 }
00364
00368 void accept() {
00369 stats.accept();
00370 statmap[hepeup.IDPRUP].accept();
00371 }
00372
00376 void reject(double w) {
00377 stats.reject(w);
00378 statmap[hepeup.IDPRUP].reject(w);
00379 }
00380
00384 virtual void increaseMaxXSec(CrossSection maxxsec);
00385
00389 tPExtrPtr partonExtractor() const { return thePartonExtractor; }
00390
00395 tCascHdlPtr CKKWHandler() const { return theCKKW; }
00396
00401 const PartonPairVec & partonBins() const { return thePartonBins; }
00402
00407 const XCombMap & xCombs() const { return theXCombs; }
00408
00412 const Cuts & cuts() const { return *theCuts; }
00413
00415
00416 protected:
00417
00420
00425 string cacheFileName() const { return theCacheFileName; }
00426
00431 bool cutEarly() const { return doCutEarly; }
00432
00436 CFile cacheFile() const { return theCacheFile;}
00437
00441 void openReadCacheFile();
00442
00446 void openWriteCacheFile();
00447
00451 void closeCacheFile();
00452
00456 bool compressedCache() const;
00457
00461 void cacheEvent() const;
00462
00466 bool uncacheEvent();
00467
00473 void reopen();
00474
00478 template <typename T>
00479 static char * mwrite(char * pos, const T & t, size_t n = 1) {
00480 std::memcpy(pos, &t, n*sizeof(T));
00481 return pos + n*sizeof(T);
00482 }
00483
00487 template <typename T>
00488 static const char * mread(const char * pos, T & t, size_t n = 1) {
00489 std::memcpy(&t, pos, n*sizeof(T));
00490 return pos + n*sizeof(T);
00491 }
00492
00494
00503 virtual bool checkPartonBin();
00504
00509 virtual void createParticles();
00510
00516 virtual tcPBPair createPartonBinInstances();
00517
00523 virtual void createBeams();
00524
00528 virtual void connectMothers();
00530
00531 public:
00532
00539 void persistentOutput(PersistentOStream & os) const;
00540
00546 void persistentInput(PersistentIStream & is, int version);
00548
00552 static void Init();
00553
00554 protected:
00555
00562 void NEvents(long x) { theNEvents = x; }
00563
00568 XCombMap & xCombs() { return theXCombs; }
00570
00578 virtual void doinit();
00579
00584 virtual void doinitrun();
00585
00590 virtual void dofinish() {
00591 close();
00592 HandlerBase::dofinish();
00593 }
00594
00599 virtual bool preInitialize() const;
00600
00605 virtual void initPDFs();
00607
00608 protected:
00609
00613 HEPRUP heprup;
00614
00618 HEPEUP hepeup;
00619
00623 tcPDPair inData;
00624
00630 pair<PDFPtr,PDFPtr> inPDF;
00631
00635 pair<cPDFPtr,cPDFPtr> outPDF;
00636
00640 PExtrPtr thePartonExtractor;
00641
00645 tCascHdlPtr theCKKW;
00646
00651 PartonPairVec thePartonBins;
00652
00657 XCombMap theXCombs;
00658
00662 CutsPtr theCuts;
00663
00668 long theNEvents;
00669
00674 long position;
00675
00679 int reopened;
00680
00686 long theMaxScan;
00687
00691 bool scanning;
00692
00696 bool isActive;
00697
00702 string theCacheFileName;
00703
00708 bool doCutEarly;
00709
00713 XSecStat stats;
00714
00718 StatMap statmap;
00719
00724 PBIPair thePartonBinInstances;
00725
00730 ObjectIndexer<long,ColourLine> colourIndex;
00731
00736 ObjectIndexer<long,Particle> particleIndex;
00737
00741 PPair theBeams;
00742
00747 PPair theIncoming;
00748
00753 PVector theOutgoing;
00754
00759 PVector theIntermediates;
00760
00764 CFile theCacheFile;
00765
00769 ReweightVector reweights;
00770
00774 ReweightVector preweights;
00775
00779 double preweight;
00780
00784 bool reweightPDF;
00785
00790 bool doInitPDFs;
00791
00798 int theMaxMultCKKW;
00799
00806 int theMinMultCKKW;
00807
00813 double lastweight;
00814
00820 double maxFactor;
00821
00826 CrossSection weightScale;
00827
00831 vector<double> xSecWeights;
00832
00837 map<int,double> maxWeights;
00838
00842 bool skipping;
00843
00847 unsigned int theMomentumTreatment;
00848
00853 bool useWeightWarnings;
00854
00855 private:
00856
00858 void setBeamA(long id);
00860 long getBeamA() const;
00862 void setBeamB(long id);
00864 long getBeamB() const;
00866 void setEBeamA(Energy e);
00868 Energy getEBeamA() const;
00870 void setEBeamB(Energy e);
00872 Energy getEBeamB() const;
00874 void setPDFA(PDFPtr);
00876 PDFPtr getPDFA() const;
00878 void setPDFB(PDFPtr);
00880 PDFPtr getPDFB() const;
00881
00882 private:
00883
00887 static AbstractClassDescription<LesHouchesReader> initLesHouchesReader;
00888
00892 LesHouchesReader & operator=(const LesHouchesReader &);
00893
00894 public:
00895
00899 class LesHouchesInconsistencyError: public Exception {};
00900
00903 class LesHouchesReopenWarning: public Exception {};
00904
00907 class LesHouchesReopenError: public Exception {};
00908
00911 class LesHouchesInitError: public InitException {};
00914 };
00915
00917 ostream & operator<<(ostream & os, const HEPEUP & h);
00918
00919 }
00920
00921
00922 #include "ThePEG/Utilities/ClassTraits.h"
00923
00924 namespace ThePEG {
00925
00932 template <>
00933 struct BaseClassTrait<LesHouchesReader,1>: public ClassTraitsType {
00935 typedef HandlerBase NthBase;
00936 };
00937
00943 template <>
00944 struct ClassTraits<LesHouchesReader>
00945 : public ClassTraitsBase<LesHouchesReader> {
00949 static string className() { return "ThePEG::LesHouchesReader"; }
00955 static string library() { return "LesHouches.so"; }
00956
00957 };
00958
00961 }
00962
00963 #endif