CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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()),
23  int(iEvent.id().luminosityBlock()),
24  int(iEvent.id().run()),
25  int(nrObjs),
26  int(std::numeric_limits<int>::max() * obj.phi() / M_PI) & 0xFFF,
27  int(objNr)};
28  uint32_t seed = 0, tries = 10;
29  do {
30  seeder.generate(&seed, &seed + 1);
31  tries++;
32  } while (seed == 0 && tries < 10);
33  return seed ? seed : iEvent.id().event() + 10000 * objNr;
34  }
35 } // namespace egamma
36 
37 #endif
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
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