meanWeight_macro.C
Go to the documentation of this file.
1 #include "CAFAna/Core/Binning.h"
2 #include "CAFAna/Cuts/Cuts.h"
3 
4 #include "CAFAna/Core/Spectrum.h"
6 
7 #include "CAFAna/Core/Var.h"
8 
9 #include "CAFAna/Vars/Vars.h"
10 
12 
13 #include <vector>
14 #include <string>
15 
16 #include "TFile.h"
17 #include "TH1.h"
18 #include "TCanvas.h"
19 
20 
23 
24 #include "Geant4WeightVars.h"
25 
26 // for POT
28 
29 // for plotting
30 #include "CAFAna/Analysis/Plots.h"
31 
32 
33 using namespace ana;
34 
36 {
37 
38  //std::cout << "BAR 1" << std::endl;
39 
40  std::string mode = "g4";
41 
42  //std::string inName = "/nova/ana/users/csweeney/final_noprimskip_cv_grid_prod5_g4rwgt_miniprod/*";
43 
44  std::string inName = "../../neardet_genie_N1810j0211a_nonswap_genierw_fhc_v08_1082_r00010402_s49_c002_R19-11-18-prod5reco.caf.root";
45  //std::string inName = "../../g4rwgt.caf.root";
46 
47  //std::cout << "BAR 2" << std::endl;
48 
49  SpectrumLoader* loader = new SpectrumLoader(inName);
50 
51  //std::cout << "BAR 3" << std::endl;
52 
53  std::string outName = "meanWeights.root";
54 
55  TFile *outFile = new TFile(outName.c_str(), "RECREATE");
56 
57  //const Cut * kSignal = new Cut(CutFromNuTruthCut(kIsNumuCC1Pi_NT && kTrueDetector_NT));
58 
59  //Cut kSignal = CutFromNuTruthCut(kIsNumuCC1Pi_NT && kTrueDetector_NT);
60  //NuTruthCut kSignal = kTrueDetector_NT;
61  //Cut kSignal = CutFromNuTruthCut(kTrueDetector_NT);
62  Cut kSignal = kTrue;
63 
64  //-----
65 
66  std::vector<Spectrum *> mySpec_vec;
67  std::vector<Spectrum *> mySpec_overflow_vec;
68 
69  Binning myBins = Binning::Simple(50, 0, 2);
70  Binning myBins_overflow = Binning::Simple(1000, 0, 90);
71 
72  std::string myLabel;
73 
74  if(mode == "g4"){
75  myLabel = "piplus single univ weights ";
76  }
77  else if(mode == "ppfx"){
78  myLabel = "ppfx single univ weights ";
79  }
80 
81  for(uint i=0; i<100; ++i){
82 
83  //std::cout << "BAR 4" << std::endl;
84 
85  //const Var kMyVar = (mode == "g4") ? kGeantPiPlusSingleUnivWeight(i) : kPPFXSingleUnivWeight(i) ;
86 
87  const Var kMyVar = kGeantPiPlusSingleUnivWeight(i);
88 
89 
90  Spectrum * sWeights_overflow = new Spectrum(myLabel.c_str(), myBins_overflow,
91  *loader, kMyVar,
92  kSignal);
93 
94  Spectrum * sWeights = new Spectrum(myLabel.c_str(), myBins,
95  *loader, kMyVar,
96  kSignal);
97 
98 
99  mySpec_overflow_vec.push_back(sWeights_overflow);
100  mySpec_vec.push_back(sWeights);
101  }
102 
103  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104 
105  //std::cout << "BAR 5" << std::endl;
106 
107 
108  loader->Go();
109 
110  //std::cout << "BAR 6" << std::endl;
111 
112  for(uint i=0; i<mySpec_vec.size(); ++i){
113 
114 
115  Spectrum * sSig = mySpec_vec[i];
116  Spectrum * sSig_overflow = mySpec_overflow_vec[i];
117 
118  std::string dir = "dir_Univ_" + std::to_string(i);
119  std::string dir_overflow = "dir_Univ_overflow_" + std::to_string(i);
120 
121  sSig->SaveTo( outFile, dir.c_str() );
122  sSig_overflow->SaveTo( outFile, dir_overflow.c_str() );
123 
124  }
125 
126  outFile->Close();
127 
128 }
129 
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kGeantPiPlusSingleUnivWeight(int i)
std::vector< double > Spectrum
Definition: Constants.h:746
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:39
TFile * outFile
Definition: PlotXSec.C:135
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:534
loader
Definition: demo0.py:10
const Cut kTrue([](const caf::SRProxy *sr){return true;})
const Cut kSignal
Definition: SINCpi0_Cuts.h:383
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
TDirectory * dir
Definition: macro.C:5
void meanWeight_macro()
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
enum BeamMode string
unsigned int uint