CMS 3D CMS Logo

EgammaRandomSeeds.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaTools_EgammaRandomSeeds_h
2 #define RecoEgamma_EgammaTools_EgammaRandomSeeds_h
3 
4 //author: Sam Harper (RAL)
5 //description:
6 // provides a seed for a random number generator based on object / event properties
7 // the supercluster method is prefered as it will be the same for electrons & photons
8 // the SC is based on seed ID and #crystals in SC, the #crystals in SC is for added
9 // entropy although this means any re-recos will change the returned number as #crystals
10 // will likely change with any re-reco while seed ID is fairly stable
11 
14 
15 #include <random>
16 
17 namespace egamma{
18 
19  uint32_t getRandomSeedFromSC(const edm::Event& iEvent,const reco::SuperClusterRef scRef);
20  template<typename T>
21  uint32_t getRandomSeedFromObj(const edm::Event& iEvent,const T& obj,size_t nrObjs,size_t objNr){
22  std::seed_seq seeder = {int(iEvent.id().event()), int(iEvent.id().luminosityBlock()), int(iEvent.id().run()),
23  int(nrObjs),int(std::numeric_limits<int>::max()*obj.phi()/M_PI) & 0xFFF,int(objNr)};
24  uint32_t seed = 0, tries = 10;
25  do {
26  seeder.generate(&seed,&seed+1); tries++;
27  } while (seed == 0 && tries < 10);
28  return seed ? seed : iEvent.id().event() + 10000*objNr;
29  }
30 }
31 
32 #endif
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
int iEvent
Definition: GenABIO.cc:224
uint32_t getRandomSeedFromObj(const edm::Event &iEvent, const T &obj, size_t nrObjs, size_t objNr)
#define M_PI
edm::EventID id() const
Definition: EventBase.h:59
uint32_t getRandomSeedFromSC(const edm::Event &iEvent, const reco::SuperClusterRef scRef)
long double T