JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
MQwMockable.h
Go to the documentation of this file.
1/**********************************************************\
2* File: MQwMockable.h *
3* *
4* Author: P. King *
5* Date: Tue Mar 29 13:08:12 EDT 2011 *
6\**********************************************************/
7
8#pragma once
9
10// System headers
11#include <functional>
12#include <random>
13
14// ROOT headers
15#include <Rtypes.h>
17class QwParameterFile;
18
19/**
20 * \class MQwMockable
21 * \ingroup QwAnalysis
22 * \brief Mix-in class enabling mock data generation for hardware channels
23 *
24 * Provides infrastructure for generating simulated data with configurable
25 * asymmetries, noise characteristics, and harmonic drifts. Supports both
26 * internal random number generation and external random variables.
27 * Used by hardware channel classes to enable Monte Carlo studies and
28 * testing without real data acquisition hardware.
29 */
31/****************************************************************//**
32 * Class: MQwMockable
33 * Mix-in class to enable mock-data generation for a
34 * data element.
35 * Only the data element classes which actually contain
36 * raw data (such as QwVQWK_Channel, QwScaler_Channel, etc.)
37 * should inherit from this class.
38 ******************************************************************/
39public:
44 {
45 // Mock drifts
46 fMockDriftAmplitude.clear();
47 fMockDriftFrequency.clear();
48 fMockDriftPhase.clear();
49 }
50 virtual ~MQwMockable() {
51 fMockDriftAmplitude.clear();
52 fMockDriftFrequency.clear();
53 fMockDriftPhase.clear();
54 }
55
56
57 /// \name Parity mock data generation
58 // @{
59 /// Load the mock data parameters from the current line in the param file.
60 virtual void LoadMockDataParameters(QwParameterFile &paramfile);
61
62 /// Set a single set of harmonic drift parameters
63 void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
64 /// Add drift parameters to the internal set
65 void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency);
66 /// Set the normal random event parameters
67 void SetRandomEventParameters(Double_t mean, Double_t sigma);
68 /// Set the helicity asymmetry
69 void SetRandomEventAsymmetry(Double_t asymmetry);
70
71 /// Seed the internal Random Variable
72 static void Seed(uint seedval){
73 fRandomnessGenerator.seed(seedval);
74 }
75
76 /// Return a random value generated either from the internal or
77 /// external Random Variable.
78 Double_t GetRandomValue();
79
80 /// Internally generate random event data
81 virtual void RandomizeEventData(int helicity = 0, double time = 0.0) = 0;
82
83//-------------------------------------------------------------------------------------------
84 virtual void SmearByResolution(double resolution) = 0;
85//-------------------------------------------------------------------------------------------
86
87 virtual void SetRawEventData() = 0;
88
89 /// Encode the event data into a CODA buffer
90 virtual void EncodeEventData(std::vector<UInt_t> &buffer) = 0;
91
92 /// Set the flag to use an externally provided random variable
94 /// Set the externally provided random variable
95 void SetExternalRandomVariable(Double_t random_variable) {
97 fExternalRandomVariable = random_variable;
98 };
99
100 // Default the mock data to be calculated with a zero-mean.
102 // @}
103
104 protected:
105 /// \name Parity mock data generation
106 // @{
107 /// Internal randomness generator
108 static std::mt19937 fRandomnessGenerator;
109 /// Internal normal probability distribution
110 static std::normal_distribution<double> fNormalDistribution;
111 /// Internal normal random variable
112 static std::function<double()> fNormalRandomVariable;
113 /// Flag to use an externally provided normal random variable
115 /// Externally provided normal random variable
117
119
120 // Parameters of the mock data
121 Double_t fMockAsymmetry; ///< Helicity asymmetry
122 Double_t fMockGaussianMean; ///< Mean of normal distribution
123 Double_t fMockGaussianSigma; ///< Sigma of normal distribution
124 std::vector<Double_t> fMockDriftAmplitude; ///< Harmonic drift amplitude
125 std::vector<Double_t> fMockDriftFrequency; ///< Harmonic drift frequency
126 std::vector<Double_t> fMockDriftPhase; ///< Harmonic drift phase
127 // @}
128};
virtual ~MQwMockable()
Definition MQwMockable.h:50
std::vector< Double_t > fMockDriftAmplitude
Harmonic drift amplitude.
double fExternalRandomVariable
Externally provided normal random variable.
static void Seed(uint seedval)
Seed the internal Random Variable.
Definition MQwMockable.h:72
std::vector< Double_t > fMockDriftFrequency
Harmonic drift frequency.
Double_t fMockAsymmetry
Helicity asymmetry.
bool fUseExternalRandomVariable
Flag to use an externally provided normal random variable.
static std::function< double()> fNormalRandomVariable
Internal normal random variable.
Definition MQwMockable.h:16
void AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Add drift parameters to the internal set.
virtual void EncodeEventData(std::vector< UInt_t > &buffer)=0
Encode the event data into a CODA buffer.
void SetExternalRandomVariable(Double_t random_variable)
Set the externally provided random variable.
Definition MQwMockable.h:95
Double_t fMockGaussianSigma
Sigma of normal distribution.
virtual void RandomizeEventData(int helicity=0, double time=0.0)=0
Internally generate random event data.
static std::normal_distribution< double > fNormalDistribution
Internal normal probability distribution.
static std::mt19937 fRandomnessGenerator
Internal randomness generator.
void SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
Set a single set of harmonic drift parameters.
Double_t fMockGaussianMean
Mean of normal distribution.
std::vector< Double_t > fMockDriftPhase
Harmonic drift phase.
void SetRandomEventAsymmetry(Double_t asymmetry)
Set the helicity asymmetry.
void SetRandomEventParameters(Double_t mean, Double_t sigma)
Set the normal random event parameters.
virtual void LoadMockDataParameters(QwParameterFile &paramfile)
Load the mock data parameters from the current line in the param file.
virtual void SetRawEventData()=0
Double_t GetRandomValue()
virtual void SmearByResolution(double resolution)=0
void UseExternalRandomVariable()
Set the flag to use an externally provided random variable.
Definition MQwMockable.h:93
bool fCalcMockDataAsDiff
void SetMockDataAsDiff()
Configuration file parser with flexible tokenization and search capabilities.