Belle II Software  release-05-01-25
TOPAssociatedPDF.cc
1 
2 /**************************************************************************
3  * BASF2 (Belle Analysis Framework 2) *
4  * Copyright(C) 2020 - Belle II Collaboration *
5  * *
6  * Author: The Belle II Collaboration *
7  * Contributors: Marko Staric *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 
12 #include <top/dataobjects/TOPAssociatedPDF.h>
13 #include <TRandom.h>
14 
15 
16 namespace Belle2 {
22  const TOPAssociatedPDF::PDFPeak* TOPAssociatedPDF::getSinglePeak() const
23  {
24  if (m_weights.empty()) return 0;
25 
26  float sum = m_BGWeight;
27  for (const auto& w : m_weights) sum += w;
28  float prob = sum * gRandom->Rndm();
29  float cum = 0;
30  for (size_t i = 0; i < m_weights.size(); i++) {
31  cum += m_weights[i];
32  if (prob < cum) return &m_peaks[i];
33  }
34  return 0;
35  }
36 
38 }
Belle2::TOPAssociatedPDF::m_BGWeight
float m_BGWeight
background weight
Definition: TOPAssociatedPDF.h:123
Belle2::TOPAssociatedPDF::getSinglePeak
const PDFPeak * getSinglePeak() const
Returns a PDF peak selected randomly according to weights.
Definition: TOPAssociatedPDF.cc:30
Belle2::TOPAssociatedPDF::m_peaks
std::vector< PDFPeak > m_peaks
collection of associated PDF peaks
Definition: TOPAssociatedPDF.h:121
Belle2::TOPAssociatedPDF::m_weights
std::vector< float > m_weights
corresponding weights
Definition: TOPAssociatedPDF.h:122
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19