LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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
 
bool IsRandomGeneratorSeeded () const
 
void SetRandomGenerator (TRandom *gen, bool isOwned)
 

Protected Member Functions

std::vector< std::string > GetConfigTokens (const std::string &config)
 

Protected Attributes

TRandom * fRndmGen
 
bool fIsOwned
 
bool fIsSeeded
 

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 56 of file EvtTimeFNALBeam.cxx.

References Config(), and SetBatchIntensities().

58  : EvtTimeShiftI(config)
59  , fTimeBetweenBuckets(1e9/53.103e6)
60  , fBucketTimeSigma(0.750)
61  , fNBucketsPerBatch(84) // NOvA-era 81+3, MINOS-era 81+5
62  , fNFilledBucketsPerBatch(81) // 81 for both eras
63  , fDisallowedBatchMask(6,0) // don't disallow any
64  , fGlobalOffset(0)
65  {
66  std::vector<double> bi(6,1.0); // 6 equal batches
68  Config(config);
69  }
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 71 of file EvtTimeFNALBeam.cxx.

71 { ; }

Member Function Documentation

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

Definition at line 252 of file EvtTimeFNALBeam.cxx.

References fCummulativeBatchPDF, fDisallowedBatchMask, and sum.

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

253  {
254  fCummulativeBatchPDF.clear();
255  double sum = 0;
256  size_t nbi = bi.size();
257  for (size_t i=0; i < nbi; ++i) {
258  sum += bi[i];
259  fCummulativeBatchPDF.push_back(sum);
260  }
261  // normalize to unit probability
262  for (size_t i=0; i < nbi; ++i) fCummulativeBatchPDF[i] /= sum;
263  // make sure the mask vector keeps up (but never make it smaller)
264  // allowing all new batches
265  if ( nbi > fDisallowedBatchMask.size() )
266  fDisallowedBatchMask.resize(nbi,0);
267 
268  /*
269  for (size_t j=0; j<nbi; ++j) {
270  std::cout << " CPDF[" << j << "] " << fCummulativeBatchPDF[j]
271  << " " << ((fDisallowedBatchMask[j])?"dis":"") << "allowed"
272  << std::endl;
273  }
274  */
275 
276  }
std::vector< int > fDisallowedBatchMask
disallow individual batches
Double_t sum
Definition: plot.C:31
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 73 of file EvtTimeFNALBeam.cxx.

References fBucketTimeSigma, fDisallowedBatchMask, fGlobalOffset, fNBucketsPerBatch, fNFilledBucketsPerBatch, fTimeBetweenBuckets, evgb::EvtTimeShiftI::GetConfigTokens(), ksigma2fwhm, and SetBatchIntensities().

Referenced by EvtTimeFNALBeam().

74  {
75  // parse config string
76  if ( config == "" ) return;
77  // GENIEHelper does a PrintConfig() when it gets this object ...
78 
79  // not the most sophisticated of parsing ... but FHICL would be overkill
80 
81  std::vector<std::string> strs = GetConfigTokens(config);
82  // strings have all been tokenized and made lowercase
83 
84  size_t nstrs = strs.size();
85  for (size_t i=0; i<nstrs; ++i) {
86  if ( strs[i] == "numi" ) {
87  fTimeBetweenBuckets = 1e9/53.103e6;
88  fBucketTimeSigma = 0.750;
89  fNBucketsPerBatch = 84; // NOvA-era 81+3, MINOS-era 81+5
90  fNFilledBucketsPerBatch = 81; // 81 for both eras
91  fDisallowedBatchMask = std::vector<int>(6,0); // don't disallow any
92  fGlobalOffset = 0;
93  std::vector<double> bi(6,1.0); // 6 equal batches
95  } else
96  if ( strs[i] == "booster" ) {
97  fTimeBetweenBuckets = 1e9/53.103e6;
98  fBucketTimeSigma = 2.0;
99  fNBucketsPerBatch = 84; //
100  fNFilledBucketsPerBatch = 81; //
101  fDisallowedBatchMask = std::vector<int>(1,0); // don't disallow any
102  fGlobalOffset = 0;
103  std::vector<double> bi(1,1.0); // 1 batch
105  } else
106  if ( strs[i].find("intensity") != std::string::npos ) {
107  // a list of batch intensities ... sets # of batches
108  // eat values up until we see the end, or a word
109  std::vector<double> bi;
110  // count how many of next tokens are numbers (crude)
111  for (size_t jj=i+1; jj<nstrs; ++jj) {
112  // very crude check of being a number
113  // can be fooled by strange text
114  size_t pos = strs[jj].find_first_not_of("0123456789.-+eE");
115  if ( pos != std::string::npos ) break;
116  // looks like a numeric value
117  double val = atof(strs[jj].c_str());
118  if ( val < 0 ) {
119  mf::LogError("EvtTime")
120  << "EvtTimeFNALBeam 'intensity' value [" << (jj-i-1)
121  << "]=" << val << " '" << strs[jj] << "' "
122  << "can't be less than zero, setting to zero";
123  val = 0;
124  }
125  bi.push_back(val);
126  }
127  // ate up some strings ... move loop index
128  i += bi.size();
129  if ( bi.empty() ) {
130  mf::LogError("EvtTime")
131  << "EvtTimeFNALBeam error 'intensity' option didn't seem to have values";
132  } else {
134  }
135  } else
136  if ( strs[i] == "bdisallowed" ) {
137  mf::LogError("EvtTime")
138  << "EvtTimeFNALBeam sorry 'bdisallowed' option not yet implemented";
139  } else {
140  // all the rest take one numeric value
141  if ( i+1 >= nstrs ) {
142  mf::LogError("EvtTime")
143  << "EvtTimeFNALBeam sorry too few values for '" << strs[i] << "'";
144  continue;
145  }
146  const char* arg = strs[i+1].c_str();
147  if ( strs[i] == "sigma" ) fBucketTimeSigma = atof(arg);
148  else if ( strs[i] == "fwhm" ) fBucketTimeSigma = atof(arg)/ksigma2fwhm;
149  else if ( strs[i] == "dtbucket" ) fTimeBetweenBuckets = atof(arg);
150  else if ( strs[i] == "nperbatch" ) fNBucketsPerBatch = atoi(arg);
151  else if ( strs[i] == "nfilled" ) fNFilledBucketsPerBatch = atoi(arg);
152  else if ( strs[i] == "global" ) fGlobalOffset = atof(arg);
153  else if ( strs[i] == "seed" ) { ; } // handled in base
154  else {
155  mf::LogError("EvtTime")
156  << "unknown EvtTimeFNALBeam config key '" << strs[i] << "'";
157  continue;
158  }
159  ++i; // used up an argument
160  }
161  }
162  // consistency check
164  mf::LogError("EvtTime")
165  << "EvtTimeFNALBeam nfilled " << fNFilledBucketsPerBatch
166  << " of " << fNBucketsPerBatch << " buckets per batch,\n"
167  << "set nfilled to match buckets per batch";
169  }
170 
171  }
void SetBatchIntensities(std::vector< double > bi)
double fGlobalOffset
always displaced by this (in ns)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
const double ksigma2fwhm
double fBucketTimeSigma
how wide is distribution in bucket
std::vector< std::string > GetConfigTokens(const std::string &config)
std::vector< int > fDisallowedBatchMask
disallow individual batches
double fTimeBetweenBuckets
time between buckets
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
std::vector< std::string > evgb::EvtTimeShiftI::GetConfigTokens ( const std::string &  config)
protectedinherited

Definition at line 69 of file EvtTimeShiftI.cxx.

References x.

Referenced by Config(), evgb::EvtTimeShiftI::EvtTimeShiftI(), and evgb::EvtTimeShiftI::IsRandomGeneratorSeeded().

70  {
71 
72  std::vector<std::string> strs;
73  if ( config == "" ) return strs;
74 
75  std::string configLocal = config;
76 
77  // blindly reduced UPPER -> lower case above to make this easier
78  // convert string to lowercase
79  std::transform(configLocal.begin(),configLocal.end(),
80  configLocal.begin(),::tolower);
81 
82  // for now make use of GENIE utilities
83  strs = genie::utils::str::Split(configLocal,"\t\n ,;=(){}[]");
84 
85  // weed out blank ones
86  strs.erase(std::remove_if(strs.begin(), strs.end(),
87  [](const std::string& x) {
88  return ( x == "") ; // put your condition here
89  }), strs.end());
90 
91  // debugging info
92  std::ostringstream msgx;
93  msgx << "Config elements:" << std::endl;
94  for (size_t j=0; j<strs.size(); ++j) {
95  msgx << " [" << std::setw(3) << j << "] -->" << strs[j] << "<--\n";
96  }
97  // this should end up as LogDebug
98  mf::LogDebug("EvtTime") << msgx.str() << std::flush;
99 
100  return strs;
101  }
Float_t x
Definition: compare.C:6
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
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.

Referenced by evgb::GENIEHelper::GENIEHelper().

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

Definition at line 62 of file EvtTimeShiftI.h.

References evgb::EvtTimeShiftI::fIsOwned.

62 { return fIsOwned; }
bool evgb::EvtTimeShiftI::IsRandomGeneratorSeeded ( ) const
inlineinherited
void evgb::EvtTimeFNALBeam::PrintConfig ( bool  verbose = true)
virtual

provide a means of printing the configuration

Implements evgb::EvtTimeShiftI.

Definition at line 209 of file EvtTimeFNALBeam.cxx.

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

210  {
211 
212  std::ostringstream msg;
213  msg << "EvtTimeFNALBeam config: \n"
214  << " TimeBetweenBuckets: " << fTimeBetweenBuckets << " ns\n"
215  << " BucketTimeSigma: " << fBucketTimeSigma << " ns "
216  << "[FWHM " << fBucketTimeSigma*ksigma2fwhm << "]\n"
217  << " NBucketsPerBatch: " << fNBucketsPerBatch << "\n"
218  << " NFilledBucketsPerBatch: " << fNFilledBucketsPerBatch << "\n"
219  << " Relative Fractions: ";
220  double prev=0;
221  for (size_t i=0; i < fCummulativeBatchPDF.size(); ++i) {
222  double frac = fCummulativeBatchPDF[i] - prev;
223  bool skip = fDisallowedBatchMask[i];
224  msg << " ";
225  if (skip) msg << "{{";
226  msg << frac;
227  if (skip) msg << "}}";
228  prev = fCummulativeBatchPDF[i];
229  }
230  msg << "\n"
231  << " GlobalOffset: " << fGlobalOffset << " ns\n";
232 
233  mf::LogInfo("EvtTime") << msg.str();
234  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
double fGlobalOffset
always displaced by this (in ns)
const double ksigma2fwhm
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 237 of file EvtTimeFNALBeam.cxx.

References CalculateCPDF().

Referenced by Config(), EvtTimeFNALBeam(), and GetNFilledBucketsPerBatch().

238  {
239  CalculateCPDF(bi);
240  }
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 242 of file EvtTimeFNALBeam.cxx.

References fCummulativeBatchPDF, and fDisallowedBatchMask.

Referenced by GetNFilledBucketsPerBatch().

243  {
244  size_t ndis = disallow.size();
245  size_t nbi = fCummulativeBatchPDF.size();
246  fDisallowedBatchMask = disallow;
247  // expand it so it's mirrors # of batch intensities
248  // but allow all that haven't been set
249  if ( nbi > ndis ) fDisallowedBatchMask.resize(nbi,0);
250  }
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 60 of file EvtTimeShiftI.cxx.

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

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

61  {
62  // deal with what we might already have
63  if ( fIsOwned ) { delete fRndmGen; fRndmGen = 0; fIsOwned = false; }
64 
65  fRndmGen = gen;
66  fIsOwned = isOwned;
67  }
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 173 of file EvtTimeFNALBeam.cxx.

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

Referenced by TimeOffset().

174  {
175  // calculate in small to large
176 
177  // pick a time within a bucket
178  double offset = fRndmGen->Gaus(0.0,fBucketTimeSigma);
179 
180  // pick a bucket within a batch
181  // assume all ~ buckets constant in batch until we have another model
182  offset += fTimeBetweenBuckets *
183  (double)fRndmGen->Integer(fNFilledBucketsPerBatch);
184 
185  // pick a bucket
186  bool disallowed = true;
187  size_t ibatch = 0;
188  size_t nbatch = fCummulativeBatchPDF.size();
189  double r = 2;
190  while ( disallowed ) {
191  r = fRndmGen->Uniform();
192  for (ibatch=0; ibatch<nbatch; ++ibatch) {
193  if ( r <= fCummulativeBatchPDF[ibatch] ) break;
194  }
195  disallowed = ( fDisallowedBatchMask[ibatch] != 0 );
196  }
197  offset += fTimeBetweenBuckets*(double)fNBucketsPerBatch*(double)ibatch;
198 
199  // finally the global offset
200  return offset + fGlobalOffset;
201  }
TRandom r
Definition: spectrum.C:23
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 203 of file EvtTimeFNALBeam.cxx.

References CalculateCPDF(), and TimeOffset().

204  {
205  CalculateCPDF(bi);
206  return TimeOffset();
207  }
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 Config(), 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(), Config(), 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 Config(), GetGlobalOffset(), PrintConfig(), SetGlobalOffset(), and TimeOffset().

bool evgb::EvtTimeShiftI::fIsOwned
protectedinherited
bool evgb::EvtTimeShiftI::fIsSeeded
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 Config(), GetTimeBetweenBuckets(), PrintConfig(), SetTimeBetweenBuckets(), and TimeOffset().


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