NeutronFates.cxx
Go to the documentation of this file.
1 // Simple record of the simulated fate of a neutron
2 //
3 // Chris Backhouse - c.backhouse@ucl.ac.uk
4 
5 #include "g4nova/NeutronFates.h"
6 
7 #include "TFile.h"
8 #include "TTree.h"
9 
10 #include <algorithm>
11 
12 namespace g4n
13 {
14  static_assert(sizeof(NeutronFate::XYZ) == 12, "sizes");
15  static_assert(sizeof(NeutronFate::Child) == 32, "sizes");
16  static_assert(sizeof(NeutronFate) == 16, "sizes");
17 
19  std::vector<NeutronFate>& out,
20  NeutronFate::Child*& childArena)
21  {
22  TFile fin(name.c_str());
23  assert(!fin.IsZombie());
24  TTree* tr = (TTree*)fin.Get("tr");
25  assert(tr);
26 
27  out.reserve(tr->GetEntries());
28 
29  NeutronFate nf;
30  tr->SetBranchAddress("nchildren", &nf.nchildren);
31 
32  long totchildren = 0;
33  for(long i = 0; i < tr->GetEntries(); ++i){
34  tr->GetEntry(i);
35  totchildren += nf.nchildren;
36  }
37  childArena = new NeutronFate::Child[totchildren];
38  NeutronFate::Child* arenaPtr = childArena;
39 
40  tr->SetBranchAddress("p", &nf.p);
41  // tr->SetBranchAddress("dt", &nf.dt);
42  // tr->SetBranchAddress("stepz", &nf.stepz);
43  // tr->SetBranchAddress("stepx", &nf.stepx);
44 
45  int childpdg[10000];
46  tr->SetBranchAddress("childpdg", &childpdg);
47  float childx[10000], childy[10000], childz[10000], childt[10000];
48  tr->SetBranchAddress("childx", &childx);
49  tr->SetBranchAddress("childy", &childy);
50  tr->SetBranchAddress("childz", &childz);
51  tr->SetBranchAddress("childt", &childt);
52  float childpx[10000], childpy[10000], childpz[10000];
53  tr->SetBranchAddress("childpx", &childpx);
54  tr->SetBranchAddress("childpy", &childpy);
55  tr->SetBranchAddress("childpz", &childpz);
56 
57  for(long i = 0; i < tr->GetEntries(); ++i){
58  tr->GetEntry(i);
59 
60  if(nf.nchildren == 0){
61  nf.children = 0;
62  }
63  else{
64  nf.children = arenaPtr;
65  for(int j = 0; j < nf.nchildren; ++j){
66  arenaPtr->dr = {childx[j], childy[j], childz[j]};
67  arenaPtr->dt = childt[j];
68  arenaPtr->p = {childpx[j], childpy[j], childpz[j]};
69  arenaPtr->pdg = childpdg[j];
70  ++arenaPtr;
71  }
72  }
73 
74  out.push_back(nf);
75  }
76 
77  assert(arenaPtr == childArena+totchildren);
78 
79  std::sort(out.begin(), out.end(), [](auto a, auto b){return a.p < b.p;});
80  }
81 }
XYZ dr
Position of the child relative to parent start (mm)
Definition: NeutronFates.h:20
TruthSlim – remove generated objects that don&#39;t contribute.
TString fin
Definition: Style.C:24
const XML_Char * name
Definition: expat.h:151
int pdg
PDG code of child particle.
Definition: NeutronFates.h:23
const Child * children
Definition: NeutronFates.h:30
float p
Initial neutron momentum (MeV)
Definition: NeutronFates.h:25
void LoadNeutronFates(const std::string &name, std::vector< NeutronFate > &out, NeutronFate::Child *&childArena)
Fills out with list of neutrons from lowest to highest energy.
float dt
Time of the child relative to parent start (ns)
Definition: NeutronFates.h:21
const double a
const double j
Definition: BetheBloch.cxx:29
XYZ p
three-momentum of child particle (MeV)
Definition: NeutronFates.h:22
const hit & b
Definition: hits.cxx:21
assert(nhit_max >=nhit_nbins)
enum BeamMode string