generate_sk_flux_histograms.C
Go to the documentation of this file.
1 //
2 // Chain JNUBEAM SuperK flux ntuples & write out flux histogram files
3 //
4 // % root
5 // root[0] .L generate_sk_flux_histograms.C++
6 // root[1] generate_sk_flux_histograms(flux_dir, file_prefix, file_suffix, min_run, max_run, Emin, Emax, Ebinsize);
7 //
8 // C.Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
9 //
10 
11 #include <cassert>
12 #include <iostream>
13 #include <sstream>
14 #include <string>
15 
16 #include <TFile.h>
17 #include <TChain.h>
18 #include <TH1D.h>
19 #include <TMath.h>
20 
21 using namespace std;
22 
24 
25  string flux_dir = "./",
26  string file_prefix = "nu.sk_flukain.",
27  string file_suffix = ".root",
28  int min_run = 0,
29  int max_run = 499,
30  double Emin = 0., /* GeV */
31  double Emax = 30., /* GeV */
32  double Ebinsz = 0.05 /* GeV */ )
33 
34 {
35  //
36  // chain
37  //
38  TChain chain("h2000", "JNUBEAM SuperK flux ntuples");
39  for(int irun = min_run; irun <= max_run; irun++) {
40  ostringstream file;
41  file << flux_dir << "/" << file_prefix << irun << file_suffix;
42  cout << "Adding file..... : " << file.str() << endl;
43  chain.AddFile(file.str().c_str());
44  }
45 
46  //
47  // book histograms
48  //
49  assert ( Emin<Emax );
50  assert ( Emin>=0. );
51  assert ( Ebinsz>0. );
52  int nbins = TMath::FloorNint((Emax-Emin)/Ebinsz);
53  TH1D * numu_flux = new TH1D("numu_flux", "numu flux at SuperK", nbins, Emin, Emax);
54  TH1D * numubar_flux = new TH1D("numubar_flux", "numubar flux at SuperK", nbins, Emin, Emax);
55  TH1D * nue_flux = new TH1D("nue_flux", "nue flux at SuperK", nbins, Emin, Emax);
56  TH1D * nuebar_flux = new TH1D("nuebar_flux", "nuebar flux at SuperK", nbins, Emin, Emax);
57 
58  //
59  // fill histograms
60  //
61  chain.Draw("Enu>>numu_flux", "norm*(mode>=11 && mode<=19)", "goff");
62  chain.Draw("Enu>>numubar_flux", "norm*(mode>=21 && mode<=29)", "goff");
63  chain.Draw("Enu>>nue_flux", "norm*(mode>=31 && mode<=39)", "goff");
64  chain.Draw("Enu>>nuebar_flux", "norm*(mode>=41 && mode<=49)", "goff");
65 
66  //
67  // save histograms
68  //
69  TFile f("./sk_flux_histograms.root", "recreate");
70  numu_flux -> Write ("numu_flux" );
71  numubar_flux -> Write ("numubar_flux");
72  nue_flux -> Write ("nue_flux" );
73  nuebar_flux -> Write ("nuebar_flux" );
74  f.Close();
75 }
const int nbins
Definition: cellShifts.C:15
chain
Check that an output directory exists.
OStream cout
Definition: OStream.cxx:6
void generate_sk_flux_histograms(string flux_dir="./", string file_prefix="nu.sk_flukain.", string file_suffix=".root", int min_run=0, int max_run=499, double Emin=0., double Emax=30., double Ebinsz=0.05)
TFile * file
Definition: cellShifts.C:17
assert(nhit_max >=nhit_nbins)
double Emax
gm Write()