/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/BesEvtGen/BesEvtGen-00-03-58/src/EvtGen/EvtGenBase/EvtPredGen.hh

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Project: BaBar detector at the SLAC PEP-II B-factory
00003  * Package: EvtGenBase
00004  *    File: $Id: EvtPredGen.hh,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
00005  *  Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
00006  *
00007  * Copyright (C) 2002 Caltech
00008  *******************************************************************************/
00009 
00010 // A predicate is applied to a generator to get another generator.
00011 // Accept-reject can be implemented in this way.
00012 //
00013 //           Predicate
00014 // Generator    ->     Generator 
00015 
00016 #ifndef EVT_PRED_GEN_HH
00017 #define EVT_PRED_GEN_HH
00018 
00019 #include <stdio.h>
00020 
00021 template <class Generator, class Predicate> 
00022 class EvtPredGen {
00023 
00024 public:
00025 
00026   typedef typename Generator::result_type result_type;
00027   
00028   EvtPredGen()
00029     : itsTried(0), itsPassed(0)
00030   {}
00031 
00032   EvtPredGen(Generator gen, Predicate pred)
00033     : itsGen(gen), itsPred(pred), itsTried(0), itsPassed(0) 
00034   {}
00035 
00036   EvtPredGen(const EvtPredGen& other)
00037     : itsGen(other.itsGen), itsPred(other.itsPred), 
00038     itsTried(other.itsTried), itsPassed(other.itsPassed)
00039   {}
00040 
00041   ~EvtPredGen()
00042   {}
00043   
00044   result_type operator()() {
00045 
00046     int i = 0;
00047     int MAX = 10000;
00048     while(i++ < MAX) {
00049 
00050       itsTried++;
00051       result_type point = itsGen();
00052       if(itsPred(point)) {
00053         itsPassed++;
00054         return point;
00055       }
00056     }    
00057     
00058     printf("No random point generated after %d attempts\n",MAX);
00059     printf("Sharp peak? Consider using pole compensation.\n");
00060     printf("I will now pick a point at random to return.\n");
00061     return itsGen();
00062   }
00063   
00064   inline int getTried() const { return itsTried; }
00065   inline int getPassed() const { return itsPassed; }
00066 
00067 protected:
00068 
00069   Generator itsGen;
00070   Predicate itsPred;
00071   int itsTried;
00072   int itsPassed;
00073 
00074 };
00075 
00076 #endif
00077 

Generated on Tue Nov 29 23:12:14 2016 for BOSS_7.0.2 by  doxygen 1.4.7