gtestFluxAtmo.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \program gtestFluxAtmo
5 
6 \brief Test program for atmospheric flux drivers
7 
8 \author Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
9  University of Liverpool & STFC Rutherford Appleton Laboratory
10 
11 \created August 22, 2005
12 
13 \cpright Copyright (c) 2003-2020, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 
16 */
17 //____________________________________________________________________________
18 
19 #include <TFile.h>
20 #include <TNtuple.h>
21 #include <TSystem.h>
22 #include <TH1D.h>
23 #include <TF1.h>
24 
29 
30 using namespace genie;
31 using namespace genie::flux;
32 
33 const unsigned int kNEvents = 100000;
34 
35 TNtuple * runGFlukaAtmo3DFluxDriver (void);
36 TNtuple * runGBartolAtmoFluxDriver (void);
37 TNtuple * createFluxNtuple (GFluxI * flux);
38 
39 //____________________________________________________________________________
40 int main(int /*argc*/, char ** /*argv*/)
41 {
42  LOG("test", pINFO) << "Running GFlukaAtmo3DFlux driver test";
43  TNtuple * ntfluka = runGFlukaAtmo3DFluxDriver();
44  ntfluka->SetTitle("GFlukaAtmo3DFlux driver data");
45 
46  LOG("test", pINFO) << "Running GBartolAtmoFlux driver test";
47  TNtuple * ntbartol = runGBartolAtmoFluxDriver();
48  ntbartol->SetTitle("GBartolAtmoFlux driver data");
49 
50  LOG("test", pINFO) << "Saving flux ntuples";
51 
52  TFile f("./genie-flux-drivers.root","recreate");
53  ntfluka -> Write("ntfluka");
54  ntbartol -> Write("ntbartol");
55  f.Close();
56 
57  LOG("test", pINFO) << "Done!";
58 
59  return 0;
60 }
61 //____________________________________________________________________________
63 {
64  string base_dir =
65  (gSystem->Getenv("GFLUX_FLUKA3DATMO") ?
66  gSystem->Getenv("GFLUX_FLUKA3DATMO") : ".");
67 
68  double Rlongitudinal = 1000.; //m
69  double Rtransverse = 100.; //m
70 
71  GFLUKAAtmoFlux * flux = new GFLUKAAtmoFlux;
72 
73  LOG("test", pINFO) << base_dir + "/sdave_numu07.dat";
74  LOG("test", pINFO) << base_dir + "/sdave_anumu07.dat";
75  LOG("test", pINFO) << base_dir + "/sdave_nue07.dat";
76  LOG("test", pINFO) << base_dir + "/sdave_anue07.dat";
77 
78 
79  flux -> AddFluxFile ( kPdgNuMu, base_dir + "/sdave_numu07.dat" );
80  flux -> AddFluxFile ( kPdgAntiNuMu, base_dir + "/sdave_anumu07.dat" );
81  flux -> AddFluxFile ( kPdgNuE, base_dir + "/sdave_nue07.dat" );
82  flux -> AddFluxFile ( kPdgAntiNuE, base_dir + "/sdave_anue07.dat" );
83  flux -> SetRadii(Rlongitudinal, Rtransverse);
84  flux -> LoadFluxData();
85  flux -> GenerateWeighted(true);
86 //flux -> ForceMaxEnergy(3);
87 
88  LOG("test", pINFO) << "Generating events";
89  TNtuple * fluxntp = createFluxNtuple(dynamic_cast<GFluxI*>(flux));
90  return fluxntp;
91 }
92 //____________________________________________________________________________
93 TNtuple * runGBartolAtmoFluxDriver(void)
94 {
95  string base_dir =
96  (gSystem->Getenv("GFLUX_BGLRS3DATMO") ?
97  gSystem->Getenv("GFLUX_BGLRS3DATMO") : ".");
98 
99  double Rlongitudinal = 1000.; //m
100  double Rtransverse = 100.; //m
101 
102  GBGLRSAtmoFlux * flux = new GBGLRSAtmoFlux;
103 
104  flux -> AddFluxFile ( kPdgNuMu, base_dir + "/f210_3_z.kam_num" );
105  flux -> AddFluxFile ( kPdgAntiNuMu, base_dir + "/f210_3_z.kam_nbm" );
106  flux -> AddFluxFile ( kPdgNuE, base_dir + "/f210_3_z.kam_nue" );
107  flux -> AddFluxFile ( kPdgAntiNuE, base_dir + "/f210_3_z.kam_nbe" );
108  flux -> SetRadii(Rlongitudinal, Rtransverse);
109  flux -> LoadFluxData();
110  flux -> GenerateWeighted(true);
111 //flux -> ForceMaxEnergy(300);
112 
113  LOG("test", pINFO) << "Generating events";
114  TNtuple * fluxntp = createFluxNtuple(dynamic_cast<GFluxI*>(flux));
115  delete flux;
116 
117  return fluxntp;
118 }
119 //____________________________________________________________________________
120 TNtuple * createFluxNtuple(GFluxI * flux)
121 {
122  TNtuple * fluxntp =
123  new TNtuple("fluxntp", "flux", "x:y:z:t:px:py:pz:E:pdgc:wght");
124 
125  LOG("test", pINFO) << "Generating flux neutrinos";
126 
127  unsigned int ievent = 0;
128  while(ievent++ < kNEvents) {
129  LOG("test", pINFO) << "Event number: " << ievent;
130  flux->GenerateNext();
131  int pdgc = flux->PdgCode();
132  double wght = flux->Weight();
133  const TLorentzVector & x4 = flux->Position();
134  const TLorentzVector & p4 = flux->Momentum();
135  fluxntp->Fill(
136  x4.X(), x4.Y(), x4.Z(), x4.T(),
137  p4.Px(), p4.Py(), p4.Pz(), p4.E(), pdgc, wght);
138  }
139  return fluxntp;
140 }
141 //____________________________________________________________________________
142 
const int kPdgNuE
Definition: PDGCodes.h:28
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
const int kPdgAntiNuE
Definition: PDGCodes.h:29
virtual const TLorentzVector & Position(void)=0
returns the flux neutrino 4-position (note: expect SI rather than physical units) ...
const int kPdgNuMu
Definition: PDGCodes.h:30
TNtuple * runGFlukaAtmo3DFluxDriver(void)
GENIE flux drivers.
int main(int, char **)
A flux driver for the FLUKA 3-D Atmospheric Neutrino Flux.
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
const unsigned int kNEvents
TNtuple * createFluxNtuple(GFluxI *flux)
const int kPdgAntiNuMu
Definition: PDGCodes.h:31
virtual bool GenerateNext(void)=0
generate the next flux neutrino (return false in err)
TNtuple * runGBartolAtmoFluxDriver(void)
virtual int PdgCode(void)=0
returns the flux neutrino pdg code
virtual const TLorentzVector & Momentum(void)=0
returns the flux neutrino 4-momentum
virtual double Weight(void)=0
returns the flux neutrino weight (if any)
hadnt Write("hadnt")
A flux driver for the Bartol Atmospheric Neutrino Flux.
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:29