|
|
|||
File indexing completed on 2026-08-06 09:38:27
0001 // -*- C++ -*- 0002 // 0003 // LesHouchesEventHandler.h is a part of ThePEG - Toolkit for HEP Event Generation 0004 // Copyright (C) 1999-2019 Leif Lonnblad 0005 // 0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details. 0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 0008 // 0009 #ifndef THEPEG_LesHouchesEventHandler_H 0010 #define THEPEG_LesHouchesEventHandler_H 0011 // 0012 // This is the declaration of the LesHouchesEventHandler class. 0013 // 0014 0015 #include "ThePEG/Handlers/EventHandler.h" 0016 #include "LesHouchesEventHandler.fh" 0017 #include "LesHouchesReader.fh" 0018 #include "ThePEG/Utilities/CompSelector.h" 0019 #include "ThePEG/Utilities/XSecStat.h" 0020 0021 namespace ThePEG { 0022 0023 0024 /** 0025 * The LesHouchesEventHandler inherits from the general EventHandler 0026 * class and administers the reading of events generated by external 0027 * matrix element generator programs according to the Les Houches 0028 * accord. 0029 * 0030 * The class has a list of <code>LesHouchesReader</code>s which 0031 * typically are connected to files with event data produced by 0032 * external matrix element generator programs. When an event is 0033 * requested by LesHouchesEventHandler, one of the readers are chosen, 0034 * an event is read in and then passed to the different 0035 * <code>StepHandler</code> defined in the underlying 0036 * EventHandler class. 0037 * 0038 * @see \ref LesHouchesEventHandlerInterfaces "The interfaces" 0039 * defined for LesHouchesEventHandler. 0040 */ 0041 class LesHouchesEventHandler: public EventHandler { 0042 0043 public: 0044 0045 /** 0046 * A vector of LesHouchesReader objects. 0047 */ 0048 typedef vector<LesHouchesReaderPtr> ReaderVector; 0049 0050 /** 0051 * A selector of readers. 0052 */ 0053 typedef CompSelector<int,CrossSection> ReaderSelector; 0054 0055 /** 0056 * Enumerate the weighting options. 0057 */ 0058 enum WeightOpt { 0059 unitweight = 1, /**< All events have unit weight. */ 0060 unitnegweight = -1, /**< All events have wight +/- 1. */ 0061 varweight = 2, /**< Varying positive weights. */ 0062 varnegweight = -2 /**< Varying positive or negative weights. */ 0063 }; 0064 0065 public: 0066 0067 /** @name Standard constructors and destructors. */ 0068 //@{ 0069 /** 0070 * The default constructor. 0071 */ 0072 LesHouchesEventHandler() 0073 : theWeightOption(unitweight), theUnitTolerance(1.0e-6), warnPNum(true), 0074 theNormWeight(0), UseLHEEvent(0) 0075 { 0076 selector().tolerance(unitTolerance()); 0077 } 0078 0079 /** 0080 * The destructor. 0081 */ 0082 virtual ~LesHouchesEventHandler(); 0083 //@} 0084 0085 public: 0086 0087 /** @name Initialization and finalization functions. */ 0088 //@{ 0089 /** 0090 * Initialize this event handler and all related objects needed to 0091 * generate events. 0092 */ 0093 virtual void initialize(); 0094 0095 /** 0096 * Write out accumulated statistics about intergrated cross sections 0097 * and stuff. 0098 */ 0099 virtual void statistics(ostream &) const; 0100 0101 /** 0102 * Histogram scale. A histogram bin which has been filled with the 0103 * weights associated with the Event objects should be scaled by 0104 * this factor to give the correct cross section. 0105 */ 0106 virtual CrossSection histogramScale() const; 0107 0108 /** 0109 * The estimated total integrated cross section of the processes 0110 * generated in this run. 0111 * @return 0 if no integrated cross section could be estimated. 0112 */ 0113 virtual CrossSection integratedXSec() const; 0114 0115 /** 0116 * The number of attempts inside the statistics object 0117 */ 0118 0119 virtual int ntriesinternal() const; 0120 0121 /** 0122 * The estimated error in the total integrated cross section of the 0123 * processes generated in this run. 0124 * @return 0 if no integrated cross section error could be estimated. 0125 */ 0126 virtual CrossSection integratedXSecErr() const; 0127 0128 /** 0129 * Map to aid the calculation of the optional weights' integrated cross section 0130 */ 0131 0132 virtual const map<string,CrossSection> & optintegratedXSecMap() const; 0133 0134 //@} 0135 0136 /** @name Functions used for the actual generation */ 0137 //@{ 0138 /** 0139 * Generate an event. 0140 */ 0141 virtual EventPtr generateEvent(); 0142 0143 /** 0144 * Create the Event and Collision objects. Used by the 0145 * generateEvent() function. 0146 */ 0147 virtual tCollPtr performCollision(); 0148 0149 /** 0150 * Continue generating an event if the generation has been stopped 0151 * before finishing. 0152 */ 0153 virtual EventPtr continueEvent(); 0154 //@} 0155 0156 /** @name Functions to manipulate statistics. */ 0157 //@{ 0158 /** 0159 * An event has been selected. Signal that an event has been 0160 * selected with the given \a weight. If unit weights are requested, 0161 * the event will be accepted with that weight. This also takes care 0162 * of the statistics collection of the selected reader object. 0163 */ 0164 void select(double weight); 0165 0166 /** 0167 * Accept the current event, taking care of the statistics 0168 * collection of the corresponding reader objects. 0169 */ 0170 void accept(); 0171 0172 /** 0173 * Reject the current event, taking care of the statistics 0174 * collection of the corresponding reader objects. 0175 */ 0176 void reject(double weight); 0177 0178 /** 0179 * Increase the overestimated cross section for the selected reader. 0180 */ 0181 void increaseMaxXSec(CrossSection maxxsec); 0182 0183 /** 0184 * Skip some events. To ensure a reader file is scanned an even 0185 * number of times, skip a number of events for the selected reader. 0186 */ 0187 void skipEvents(); 0188 0189 //@} 0190 0191 /** @name Simple access functions. */ 0192 //@{ 0193 /** 0194 * The way weights are to be treated. 0195 */ 0196 WeightOpt weightOption() const { return theWeightOption; } 0197 0198 /** 0199 * If the weight option is set to unit weight, do not start 0200 * compensating unless the weight is this much larger than unity. 0201 */ 0202 double unitTolerance() const { return theUnitTolerance; } 0203 0204 /** 0205 * Access the list of readers. 0206 */ 0207 const ReaderVector & readers() const { return theReaders; } 0208 0209 /** 0210 * The selector to choose readers according to their overestimated 0211 * cross section. 0212 */ 0213 const ReaderSelector & selector() const { return theSelector; } 0214 0215 /** 0216 * The currently selected reader object. 0217 */ 0218 tLesHouchesReaderPtr currentReader() const { return theCurrentReader; } 0219 0220 0221 /** 0222 * Set the currently selected reader object. 0223 */ 0224 void currentReader(tLesHouchesReaderPtr x) { theCurrentReader = x; } 0225 0226 //@} 0227 0228 public: 0229 0230 /** @name Functions used by the persistent I/O system. */ 0231 //@{ 0232 /** 0233 * Function used to write out object persistently. 0234 * @param os the persistent output stream written to. 0235 */ 0236 void persistentOutput(PersistentOStream & os) const; 0237 0238 /** 0239 * Function used to read in object persistently. 0240 * @param is the persistent input stream read from. 0241 * @param version the version number of the object when written. 0242 */ 0243 void persistentInput(PersistentIStream & is, int version); 0244 //@} 0245 0246 /** 0247 * The standard Init function used to initialize the interfaces. 0248 * Called exactly once for each class by the class description system 0249 * before the main function starts or 0250 * when this class is dynamically loaded. 0251 */ 0252 static void Init(); 0253 0254 /** 0255 * The currently selected reader object. 0256 */ 0257 tLesHouchesReaderPtr theCurrentReader; 0258 0259 protected: 0260 0261 /** @name Clone Methods. */ 0262 //@{ 0263 /** 0264 * Make a simple clone of this object. 0265 * @return a pointer to the new object. 0266 */ 0267 virtual IBPtr clone() const; 0268 0269 /** Make a clone of this object, possibly modifying the cloned object 0270 * to make it sane. 0271 * @return a pointer to the new object. 0272 */ 0273 virtual IBPtr fullclone() const; 0274 //@} 0275 0276 protected: 0277 0278 /** @name Standard Interfaced functions. */ 0279 //@{ 0280 /** 0281 * Initialize this object after the setup phase before saving an 0282 * EventGenerator to disk. 0283 * @throws InitException if object could not be initialized properly. 0284 */ 0285 virtual void doinit(); 0286 0287 /** 0288 * Initialize this object. Called in the run phase just before 0289 * a run begins. 0290 */ 0291 virtual void doinitrun(); 0292 0293 /** 0294 * Finalize this object. Called in the run phase just after a 0295 * run has ended. Used eg. to write out statistics. 0296 */ 0297 virtual void dofinish(); 0298 //@} 0299 0300 protected: 0301 0302 /** 0303 * Access the list of readers. 0304 */ 0305 ReaderVector & readers() { return theReaders; } 0306 0307 /** 0308 * The selector to choose readers according to their overestimated 0309 * cross section. 0310 */ 0311 ReaderSelector & selector() { return theSelector; } 0312 0313 /** 0314 * Helper function for the interface; 0315 */ 0316 void setUnitTolerance(double); 0317 0318 /** 0319 * Collect statistics for this event handler. 0320 */ 0321 XSecStat stats; 0322 0323 /** 0324 * Collect statistics for this event handler. To be used for 0325 * histogram scaling. 0326 */ 0327 XSecStat histStats; 0328 0329 /** 0330 * The weight identifiers for the events 0331 */ 0332 0333 vector<string> weightnames; 0334 0335 /** 0336 * Collect statistics for this event handler's optional weights. 0337 */ 0338 struct OptWeight { 0339 0340 /** 0341 * Collect statistics for the optional weights 0342 */ 0343 XSecStat stats; 0344 0345 /** 0346 * Calculate the cross section for the optional weights 0347 */ 0348 CrossSection xs; 0349 0350 /** 0351 * Collect statistics for this event handler's optional weights. To be used for 0352 * histogram scaling. 0353 */ 0354 XSecStat histStats; 0355 }; 0356 0357 /** Map statistics to weight name strings */ 0358 map <string,OptWeight> opt; 0359 0360 /** 0361 * Counter for the number of tries for the purpose of statistics 0362 */ 0363 0364 int ntries; 0365 0366 /** 0367 * Return the optional weights' statistics 0368 */ 0369 0370 const map<string,OptWeight> & optWeights() const { return opt; } 0371 0372 private: 0373 0374 /** 0375 * The list of readers. 0376 */ 0377 ReaderVector theReaders; 0378 0379 /** 0380 * The selector to choose readers according to their overestimated 0381 * cross section. 0382 */ 0383 ReaderSelector theSelector; 0384 0385 /** 0386 * The way weights are to be treated. 0387 */ 0388 WeightOpt theWeightOption; 0389 0390 /** 0391 * If the weight option is set to unit weight, do not start 0392 * compensating unless the weight is this much larger than unity. 0393 */ 0394 double theUnitTolerance; 0395 0396 0397 /** 0398 * Warn if the same process number is used in more than one 0399 * LesHouchesReader. 0400 */ 0401 bool warnPNum; 0402 0403 /** 0404 * How to normalize the weights 0405 */ 0406 unsigned int theNormWeight; 0407 0408 /** 0409 * How to number the events 0410 */ 0411 unsigned int UseLHEEvent; 0412 0413 public: 0414 0415 /** @cond EXCEPTIONCLASSES */ 0416 /** 0417 * Exception class used if no readers were assigned. 0418 */ 0419 class LesHouchesInitError: public InitException {}; 0420 0421 /** 0422 * Exception class used if the same process number is used by more 0423 * than ne reader. 0424 */ 0425 class LesHouchesPNumException: public InitException {}; 0426 /** @endcond */ 0427 0428 private: 0429 0430 /** 0431 * The static object used to initialize the description of this class. 0432 * Indicates that this is a concrete class with persistent data. 0433 */ 0434 static ClassDescription<LesHouchesEventHandler> initLesHouchesEventHandler; 0435 0436 /** 0437 * The assignment operator is private and must never be called. 0438 * In fact, it should not even be implemented. 0439 */ 0440 LesHouchesEventHandler & operator=(const LesHouchesEventHandler &) = delete; 0441 0442 }; 0443 0444 } 0445 0446 // CLASSDOC OFF 0447 0448 #include "ThePEG/Utilities/ClassTraits.h" 0449 0450 namespace ThePEG { 0451 0452 /** @cond TRAITSPECIALIZATIONS */ 0453 0454 /** This template specialization informs ThePEG about the 0455 * base classes of LesHouchesEventHandler. */ 0456 template <> 0457 struct BaseClassTrait<LesHouchesEventHandler,1> { 0458 /** Typedef of the first base class of LesHouchesEventHandler. */ 0459 typedef EventHandler NthBase; 0460 }; 0461 0462 /** This template specialization informs ThePEG about the name of 0463 * the LesHouchesEventHandler class and the shared object where it is defined. */ 0464 template <> 0465 struct ClassTraits<LesHouchesEventHandler> 0466 : public ClassTraitsBase<LesHouchesEventHandler> { 0467 /** Return a platform-independent class name */ 0468 static string className() { return "ThePEG::LesHouchesEventHandler"; } 0469 /** Return the name of the shared library be loaded to get access to 0470 * the LesHouchesEventHandler class and every other class it uses 0471 * (except the base class). */ 0472 static string library() { return "LesHouches.so"; } 0473 }; 0474 0475 /** @endcond */ 0476 0477 } 0478 0479 #endif /* THEPEG_LesHouchesEventHandler_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|