Project
Loading...
Searching...
No Matches
TopologyFastSimulation.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18#include <algorithm>
19
21
22namespace o2
23{
24namespace itsmft
25{
26TopologyFastSimulation::TopologyFastSimulation(std::string fileName, unsigned seed)
27{
28 mDictionary.readFromFile(fileName);
29 double tot_freq = 0.;
30 int dictSize = mDictionary.getSize();
31 mFreqArray.reserve(dictSize);
32 for (int iKey = 0; iKey < dictSize; iKey++) {
33 tot_freq += mDictionary.getFrequency(iKey);
34 mFreqArray[iKey] = tot_freq;
35 }
36 mGenerator = std::mt19937(seed);
37 mDistribution = std::uniform_real_distribution<double>(0.0, 1.0);
38}
39
41{
42 double rnd = mDistribution(mGenerator);
43 auto ind = std::upper_bound(mFreqArray.begin(), mFreqArray.end(), rnd,
44 [](const double& comp1, const double& comp2) { return comp1 < comp2; });
45 return std::distance(mFreqArray.begin(), ind);
46}
47} // namespace itsmft
48} // namespace o2
ClassImp(o2::itsmft::TopologyFastSimulation)
Definition of the TopologyFastSimulation class.
int getSize() const
Returns the number of elements in the dicionary;.
int readFromFile(const std::string &fileName)
double getFrequency(int n) const
Returns the frequency of the n_th element;.
TopologyFastSimulation(std::string fileName, unsigned seed=0xdeadbeef)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...