LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
EvtTimeFNALBeam.cxx
Go to the documentation of this file.
1 
12 #include "EvtTimeFNALBeam.h"
13 #include "EvtTimeShiftFactory.h"
15 
16 #include <iostream>
17 
18 namespace evgb {
19 
20  EvtTimeFNALBeam::EvtTimeFNALBeam(const std::string& config)
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  }
33 
35 
36  void EvtTimeFNALBeam::Config(const std::string& config)
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  }
51 
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  }
81 
82  double EvtTimeFNALBeam::TimeOffset(std::vector<double> bi)
83  {
84  CalculateCPDF(bi);
85  return TimeOffset();
86  }
87 
88  void EvtTimeFNALBeam::PrintConfig(bool /* verbose */)
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  }
109 
110 
111  void EvtTimeFNALBeam::SetBatchIntensities(std::vector<double> bi)
112  {
113  CalculateCPDF(bi);
114  }
115 
116  void EvtTimeFNALBeam::SetDisallowedBatchMask(std::vector<int> disallow)
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  }
125 
126  void EvtTimeFNALBeam::CalculateCPDF(std::vector<double> bi)
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  }
151 
152 
153 } // namespace evgb
void SetBatchIntensities(std::vector< double > bi)
double fGlobalOffset
always displaced by this (in ns)
configurable FNAL Beam time distribution
EvtTimeFNALBeam(const std::string &config)
double fBucketTimeSigma
how wide is distribution in bucket
interface for event time distribution
Definition: EvtTimeShiftI.h:29
virtual void PrintConfig(bool verbose=true)
provide a means of printing the configuration
void CalculateCPDF(std::vector< double > batchi)
virtual void Config(const std::string &config)
virtual double TimeOffset()
std::vector< int > fDisallowedBatchMask
disallow individual batches
double fTimeBetweenBuckets
time between buckets
A class for generating concrete EvtTimeShiftI derived classes based on the factory pattern...
Physics generators for neutrinos, cosmic rays, and others.
Definition: CRYHelper.cxx:33
std::vector< double > fCummulativeBatchPDF
summed prob for batches
void SetDisallowedBatchMask(std::vector< int > disallow)
#define TIMESHIFTREG3(_ns, _name, _fqname)