EDepSimSpillTimeGenerator.cc
Go to the documentation of this file.
3 
4 #include <EDepSimLog.hh>
5 
6 #include <G4PhysicalConstants.hh>
7 #include <Randomize.hh>
8 
10  G4String name, double spillTime, double bunchSeparation,
11  double bunchLength, const std::vector<double>& bunchPower)
12  : EDepSim::VTimeGenerator(name), fSpillTime(spillTime),
13  fBunchSeparation(bunchSeparation), fBunchLength(bunchLength),
14  fBunchPower(bunchPower) {
15  if (fBunchPower.size()<1) fBunchPower.push_back(1.0);
16  fMaxPower = 0.0;
18  b != fBunchPower.end();
19  ++b) {
20  if (fMaxPower<(*b)) fMaxPower = *b;
21  }
22 
23  if (fMaxPower<0.001) {
24  EDepSimError("Spill created without any power in bunchs");
25  }
26 }
27 
29 
30 double EDepSim::SpillTimeGenerator::GetTime(const G4LorentzVector& vtx) {
31  // Choose a spill;
32  int spills = fBunchPower.size();
33  int spill = 0;
34  do {
35  spill = int(spills*G4UniformRand());
36  if (spill>=spills) spill=spills-1;
37  if (spill<0) spill = 0;
38  } while (fBunchPower[spill]<fMaxPower*G4UniformRand());
39 
40  // Get the spill start time. This assumes the neutrino wave is traveling
41  // along the positive Z axis.
42  double time = fSpillTime + vtx.z()/c_light + spill*fBunchSeparation;
43 
44  // Adjust the time in the bunch.
45  double truncTime = G4RandGauss::shoot(0.0, 1.0);
46  while (truncTime < -2.0 || truncTime > 2.0) {
47  truncTime = G4RandGauss::shoot(0.0, 1.0);
48  }
49  time += fBunchLength*truncTime;
50 
51  return time;
52 }
53 
55  return true;
56 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
double fBunchSeparation
The time between bunch starts.
double fBunchLength
The length of a bunch. This is the gaussian width of the bunch.
SpillTimeGenerator(G4String name, double spillTime, double bunchSeparation, double bunchLength, const std::vector< double > &bunchPower)
Construct a module from components.
Definition: TG4HitSegment.h:10
double fMaxPower
The maximum power in a bunch.
double fSpillTime
The time that the neutrinos are crossing (0,0,0).
#define EDepSimError(outStream)
Definition: EDepSimLog.hh:503
double GetTime(const G4LorentzVector &vertex)
Return the time of the event to be generated.
static bool * b
Definition: config.cpp:1043
std::vector< double > fBunchPower
The power in each bunch.