LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
evgb::EvtTimeFNALBeam Class Reference

configurable FNAL Beam time distribution More...

#include "EvtTimeFNALBeam.h"

Inheritance diagram for evgb::EvtTimeFNALBeam:
evgb::EvtTimeShiftI

Public Member Functions

 EvtTimeFNALBeam (const std::string &config)
 
virtual ~EvtTimeFNALBeam ()
 
virtual void Config (const std::string &config)
 
virtual double TimeOffset ()
 
virtual double TimeOffset (std::vector< double > bi)
 
virtual void PrintConfig (bool verbose=true)
 provide a means of printing the configuration More...
 
void SetTimeBetweenBuckets (double val)
 specific methods for this variant More...
 
double GetTimeBetweenBuckets () const
 
void SetBucketTimeSigma (double val)
 
double GetBucketTimeSigma () const
 
void SetNBucketsPerBatch (int ival)
 
int GetNBucketsPerBatch () const
 
void SetNFilledBucketsPerBatch (int ival)
 
int GetNFilledBucketsPerBatch () const
 
void SetBatchIntensities (std::vector< double > bi)
 
void SetDisallowedBatchMask (std::vector< int > disallow)
 
void SetGlobalOffset (double val)
 
double GetGlobalOffset () const
 
TRandom * GetRandomGenerator () const
 
bool IsRandomGeneratorOwned () const
 
void SetRandomGenerator (TRandom *gen, bool isOwned)
 

Protected Attributes

TRandom * fRndmGen
 
bool fIsOwned
 

Private Member Functions

void CalculateCPDF (std::vector< double > batchi)
 

Private Attributes

double fTimeBetweenBuckets
 time between buckets More...
 
double fBucketTimeSigma
 how wide is distribution in bucket More...
 
int fNBucketsPerBatch
 
int fNFilledBucketsPerBatch
 
std::vector< double > fCummulativeBatchPDF
 summed prob for batches More...
 
std::vector< int > fDisallowedBatchMask
 disallow individual batches More...
 
double fGlobalOffset
 always displaced by this (in ns) More...
 

Detailed Description

configurable FNAL Beam time distribution

Author
Robert Hatcher <rhatcher fnal.gov> Fermi National Accelerator Laboratory

2015-06-22

Version
Id
EvtTimeFNALBeam.h,v 1.1 2015/06/30 18:01:24 rhatcher Exp

Definition at line 22 of file EvtTimeFNALBeam.h.

Constructor & Destructor Documentation

evgb::EvtTimeFNALBeam::EvtTimeFNALBeam ( const std::string &  config)

Definition at line 20 of file EvtTimeFNALBeam.cxx.

References Config(), and SetBatchIntensities().

21  : EvtTimeShiftI(config)
22  , fTimeBetweenBuckets(1e9/53.103e6)
23  , fBucketTimeSigma(0.750)
24  , fNBucketsPerBatch(84) // NOvA-era 81+3, MINOS-era 81+5
25  , fNFilledBucketsPerBatch(81) // 81 for both eras
26  , fDisallowedBatchMask(6,0) // don't disallow any
27  , fGlobalOffset(0)
28  {
29  std::vector<double> bi(6,1.0); // 6 equal batches
31  Config(config);
32  }
void SetBatchIntensities(std::vector< double > bi)
double fGlobalOffset
always displaced by this (in ns)
double fBucketTimeSigma
how wide is distribution in bucket
virtual void Config(const std::string &config)
EvtTimeShiftI(const std::string &config)
std::vector< int > fDisallowedBatchMask
disallow individual batches
double fTimeBetweenBuckets
time between buckets
evgb::EvtTimeFNALBeam::~EvtTimeFNALBeam ( )
virtual

Definition at line 34 of file EvtTimeFNALBeam.cxx.

34 { ; }

Member Function Documentation

void evgb::EvtTimeFNALBeam::CalculateCPDF ( std::vector< double >  batchi)
private

Definition at line 126 of file EvtTimeFNALBeam.cxx.

References fCummulativeBatchPDF, and fDisallowedBatchMask.

Referenced by GetGlobalOffset(), SetBatchIntensities(), and TimeOffset().

127  {
128  fCummulativeBatchPDF.clear();
129  double sum = 0;
130  size_t nbi = bi.size();
131  for (size_t i=0; i < nbi; ++i) {
132  sum += bi[i];
133  fCummulativeBatchPDF.push_back(sum);
134  }
135  // normalize to unit probability
136  for (size_t i=0; i < nbi; ++i) fCummulativeBatchPDF[i] /= sum;
137  // make sure the mask vector keeps up (but never make it smaller)
138  // allowing all new batches
139  if ( nbi > fDisallowedBatchMask.size() )
140  fDisallowedBatchMask.resize(nbi,0);
141 
142  /*
143  for (size_t j=0; j<nbi; ++j) {
144  std::cout << " CPDF[" << j << "] " << fCummulativeBatchPDF[j]
145  << " " << ((fDisallowedBatchMask[j])?"dis":"") << "allowed"
146  << std::endl;
147  }
148  */
149 
150  }
std::vector< int > fDisallowedBatchMask
disallow individual batches
std::vector< double > fCummulativeBatchPDF
summed prob for batches
void evgb::EvtTimeFNALBeam::Config ( const std::string &  config)
virtual

each schema must take a string that configures it it is up to the individual model to parse said string and extract parameters

Implements evgb::EvtTimeShiftI.

Definition at line 36 of file EvtTimeFNALBeam.cxx.

References PrintConfig().

Referenced by EvtTimeFNALBeam().

37  {
38  // parse config string
39  if ( config != "" ) {
40  std::cerr
41  << "!!!!! EvtTimeFNALBeam - not yet up to parsing Config string "
42  << ", ignoring:"
43  << std::endl
44  << "\"" << config << "\""
45  << std::endl
46  << "Starting with: "
47  << std::endl;
48  PrintConfig();
49  }
50  }
virtual void PrintConfig(bool verbose=true)
provide a means of printing the configuration
double evgb::EvtTimeFNALBeam::GetBucketTimeSigma ( ) const
inline

Definition at line 51 of file EvtTimeFNALBeam.h.

References fBucketTimeSigma.

51 { return fBucketTimeSigma; }
double fBucketTimeSigma
how wide is distribution in bucket
double evgb::EvtTimeFNALBeam::GetGlobalOffset ( ) const
inline

Definition at line 61 of file EvtTimeFNALBeam.h.

References CalculateCPDF(), and fGlobalOffset.

61 { return fGlobalOffset; }
double fGlobalOffset
always displaced by this (in ns)
int evgb::EvtTimeFNALBeam::GetNBucketsPerBatch ( ) const
inline

Definition at line 53 of file EvtTimeFNALBeam.h.

References fNBucketsPerBatch.

int evgb::EvtTimeFNALBeam::GetNFilledBucketsPerBatch ( ) const
inline
TRandom* evgb::EvtTimeShiftI::GetRandomGenerator ( ) const
inlineinherited

Allow users some control over random # sequences An "owned" object is expected to be deleted by the EvtTimeShift obj

Definition at line 61 of file EvtTimeShiftI.h.

References evgb::EvtTimeShiftI::fRndmGen.

61 { return fRndmGen; }
double evgb::EvtTimeFNALBeam::GetTimeBetweenBuckets ( ) const
inline

Definition at line 49 of file EvtTimeFNALBeam.h.

References fTimeBetweenBuckets.

49 { return fTimeBetweenBuckets; }
double fTimeBetweenBuckets
time between buckets
bool evgb::EvtTimeShiftI::IsRandomGeneratorOwned ( ) const
inlineinherited
void evgb::EvtTimeFNALBeam::PrintConfig ( bool  verbose = true)
virtual

provide a means of printing the configuration

Implements evgb::EvtTimeShiftI.

Definition at line 88 of file EvtTimeFNALBeam.cxx.

References fBucketTimeSigma, fCummulativeBatchPDF, fDisallowedBatchMask, fGlobalOffset, fNBucketsPerBatch, fNFilledBucketsPerBatch, and fTimeBetweenBuckets.

Referenced by Config().

89  {
90  std::cout << "EvtTimeFNALBeam config: " << std::endl
91  << " TimeBetweenBuckets: " << fTimeBetweenBuckets << " ns" << std::endl
92  << " BucketTimeSigma: " << fBucketTimeSigma << " ns" << std::endl
93  << " NBucketsPerBatch: " << fNBucketsPerBatch << std::endl
94  << " NFilledBucketsPerBatch: " << fNFilledBucketsPerBatch << std::endl
95  << " Relative Fractions: ";
96  double prev=0;
97  for (size_t i=0; i < fCummulativeBatchPDF.size(); ++i) {
98  double frac = fCummulativeBatchPDF[i] - prev;
99  bool skip = fDisallowedBatchMask[i];
100  std::cout << " ";
101  if (skip) std::cout << "{{";
102  std::cout << frac;
103  if (skip) std::cout << "}}";
104  prev = fCummulativeBatchPDF[i];
105  }
106  std::cout << std::endl
107  << " GlobalOffset: " << fGlobalOffset << " ns" << std::endl;
108  }
double fGlobalOffset
always displaced by this (in ns)
double fBucketTimeSigma
how wide is distribution in bucket
std::vector< int > fDisallowedBatchMask
disallow individual batches
double fTimeBetweenBuckets
time between buckets
std::vector< double > fCummulativeBatchPDF
summed prob for batches
void evgb::EvtTimeFNALBeam::SetBatchIntensities ( std::vector< double >  bi)

Definition at line 111 of file EvtTimeFNALBeam.cxx.

References CalculateCPDF().

Referenced by EvtTimeFNALBeam(), and GetNFilledBucketsPerBatch().

112  {
113  CalculateCPDF(bi);
114  }
void CalculateCPDF(std::vector< double > batchi)
void evgb::EvtTimeFNALBeam::SetBucketTimeSigma ( double  val)
inline

Definition at line 50 of file EvtTimeFNALBeam.h.

References fBucketTimeSigma.

50 { fBucketTimeSigma=val; }
double fBucketTimeSigma
how wide is distribution in bucket
void evgb::EvtTimeFNALBeam::SetDisallowedBatchMask ( std::vector< int >  disallow)

Definition at line 116 of file EvtTimeFNALBeam.cxx.

References fCummulativeBatchPDF, and fDisallowedBatchMask.

Referenced by GetNFilledBucketsPerBatch().

117  {
118  size_t ndis = disallow.size();
119  size_t nbi = fCummulativeBatchPDF.size();
120  fDisallowedBatchMask = disallow;
121  // expand it so it's mirrors # of batch intensities
122  // but allow all that haven't been set
123  if ( nbi > ndis ) fDisallowedBatchMask.resize(nbi,0);
124  }
std::vector< int > fDisallowedBatchMask
disallow individual batches
std::vector< double > fCummulativeBatchPDF
summed prob for batches
void evgb::EvtTimeFNALBeam::SetGlobalOffset ( double  val)
inline

Definition at line 60 of file EvtTimeFNALBeam.h.

References fGlobalOffset.

60 { fGlobalOffset=val; }
double fGlobalOffset
always displaced by this (in ns)
void evgb::EvtTimeFNALBeam::SetNBucketsPerBatch ( int  ival)
inline

Definition at line 52 of file EvtTimeFNALBeam.h.

References fNBucketsPerBatch.

void evgb::EvtTimeFNALBeam::SetNFilledBucketsPerBatch ( int  ival)
inline

Definition at line 54 of file EvtTimeFNALBeam.h.

References fNFilledBucketsPerBatch.

void evgb::EvtTimeShiftI::SetRandomGenerator ( TRandom *  gen,
bool  isOwned 
)
inherited

Definition at line 28 of file EvtTimeShiftI.cxx.

References evgb::EvtTimeShiftI::fIsOwned, and evgb::EvtTimeShiftI::fRndmGen.

Referenced by evgb::EvtTimeShiftI::IsRandomGeneratorOwned().

29  {
30  // deal with what we might already have
31  if ( fIsOwned ) { delete fRndmGen; fRndmGen = 0; fIsOwned = false; }
32 
33  fRndmGen = gen;
34  fIsOwned = isOwned;
35  }
void evgb::EvtTimeFNALBeam::SetTimeBetweenBuckets ( double  val)
inline

specific methods for this variant

Definition at line 48 of file EvtTimeFNALBeam.h.

References fTimeBetweenBuckets.

48 { fTimeBetweenBuckets=val; }
double fTimeBetweenBuckets
time between buckets
double evgb::EvtTimeFNALBeam::TimeOffset ( )
virtual

return time within a 'record' in nanoseconds version taking array might be used for relative batch fractions that vary on a record-by-record basis

Implements evgb::EvtTimeShiftI.

Definition at line 52 of file EvtTimeFNALBeam.cxx.

References fBucketTimeSigma, fCummulativeBatchPDF, fDisallowedBatchMask, fGlobalOffset, fNBucketsPerBatch, fNFilledBucketsPerBatch, evgb::EvtTimeShiftI::fRndmGen, and fTimeBetweenBuckets.

Referenced by TimeOffset().

53  {
54  // calculate in small to large
55 
56  // pick a time within a bucket
57  double offset = fRndmGen->Gaus(0.0,fBucketTimeSigma);
58 
59  // pick a bucket within a batch
60  // assume all ~ buckets constant in batch until we have another model
61  offset += fTimeBetweenBuckets *
62  (double)fRndmGen->Integer(fNFilledBucketsPerBatch);
63 
64  // pick a bucket
65  bool disallowed = true;
66  size_t ibatch = 0;
67  size_t nbatch = fCummulativeBatchPDF.size();
68  double r = 2;
69  while ( disallowed ) {
70  r = fRndmGen->Uniform();
71  for (ibatch=0; ibatch<nbatch; ++ibatch) {
72  if ( r <= fCummulativeBatchPDF[ibatch] ) break;
73  }
74  disallowed = ( fDisallowedBatchMask[ibatch] != 0 );
75  }
76  offset += fTimeBetweenBuckets*(double)fNBucketsPerBatch*(double)ibatch;
77 
78  // finally the global offset
79  return offset + fGlobalOffset;
80  }
double fGlobalOffset
always displaced by this (in ns)
double fBucketTimeSigma
how wide is distribution in bucket
std::vector< int > fDisallowedBatchMask
disallow individual batches
double fTimeBetweenBuckets
time between buckets
std::vector< double > fCummulativeBatchPDF
summed prob for batches
double evgb::EvtTimeFNALBeam::TimeOffset ( std::vector< double >  bi)
virtual

Implements evgb::EvtTimeShiftI.

Definition at line 82 of file EvtTimeFNALBeam.cxx.

References CalculateCPDF(), and TimeOffset().

83  {
84  CalculateCPDF(bi);
85  return TimeOffset();
86  }
void CalculateCPDF(std::vector< double > batchi)
virtual double TimeOffset()

Member Data Documentation

double evgb::EvtTimeFNALBeam::fBucketTimeSigma
private

how wide is distribution in bucket

Definition at line 68 of file EvtTimeFNALBeam.h.

Referenced by GetBucketTimeSigma(), PrintConfig(), SetBucketTimeSigma(), and TimeOffset().

std::vector<double> evgb::EvtTimeFNALBeam::fCummulativeBatchPDF
private

summed prob for batches

Definition at line 71 of file EvtTimeFNALBeam.h.

Referenced by CalculateCPDF(), PrintConfig(), SetDisallowedBatchMask(), and TimeOffset().

std::vector<int> evgb::EvtTimeFNALBeam::fDisallowedBatchMask
private

disallow individual batches

Definition at line 72 of file EvtTimeFNALBeam.h.

Referenced by CalculateCPDF(), PrintConfig(), SetDisallowedBatchMask(), and TimeOffset().

double evgb::EvtTimeFNALBeam::fGlobalOffset
private

always displaced by this (in ns)

Definition at line 73 of file EvtTimeFNALBeam.h.

Referenced by GetGlobalOffset(), PrintConfig(), SetGlobalOffset(), and TimeOffset().

bool evgb::EvtTimeShiftI::fIsOwned
protectedinherited
int evgb::EvtTimeFNALBeam::fNBucketsPerBatch
private
int evgb::EvtTimeFNALBeam::fNFilledBucketsPerBatch
private
double evgb::EvtTimeFNALBeam::fTimeBetweenBuckets
private

time between buckets

Definition at line 67 of file EvtTimeFNALBeam.h.

Referenced by GetTimeBetweenBuckets(), PrintConfig(), SetTimeBetweenBuckets(), and TimeOffset().


The documentation for this class was generated from the following files: