Classes | Typedefs | Functions | Variables
Geant4ReweightSysts.cc File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "cetlib/filepath_maker.h"
#include "fhiclcpp/ParameterSet.h"
#include "ProtoDUNESelectionUtils.h"
#include "TFile.h"

Go to the source code of this file.

Classes

struct  systConfig
 

Typedefs

typedef std::vector< std::stringstring_v
 
typedef std::vector< int > int_v
 
typedef std::vector< double > double_v
 

Functions

bool parseArgs (int argc, char **argv)
 
fhicl::ParameterSet makeParameterSet (std::string file)
 
void saveHists (std::vector< TH1 * > &vec)
 
void makeFracErrorHist (TH1 *variation, TH1 *nominal)
 
int main (int argc, char **argv)
 

Variables

std::string output_file_name
 
std::string fcl_file_name
 

Typedef Documentation

typedef std::vector<double> double_v

Definition at line 28 of file Geant4ReweightSysts.cc.

typedef std::vector<int> int_v

Definition at line 27 of file Geant4ReweightSysts.cc.

Definition at line 26 of file Geant4ReweightSysts.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 74 of file Geant4ReweightSysts.cc.

74  {
75 
76  if (!parseArgs(argc, argv)) return 0;
77 
79 
80  systConfig cfg(pset);
81  double tmin = cfg.TruthBinning[0];
82  double tmax = cfg.TruthBinning.back();
83 
84  std::vector<TH1 *> bg_syst_hists;
85  std::vector<TH1 *> bg_nom_hists;
86  std::vector<TH1 *> sig_syst_hists;
87  std::vector<TH1 *> sig_nom_hists;
88  std::vector<TH1 *> inc_nom_hists;
89  std::vector<TH1 *> inc_syst_hists;
90 
91  for (size_t i = 0; i < cfg.ChannelNames.size(); ++i) {
92 
93  //Backgrounds
94  for (size_t j = 0; j < cfg.BackgroundTopology.size(); ++j) {
95  int topo = cfg.BackgroundTopology[j];
96 
97  //Get nominal
98  bg_nom_hists.push_back(
100  cfg.MCFileNames[i], cfg.RecoTreeName, cfg.RecoBinning,
101  cfg.ChannelNames[i], cfg.BackgroundTopologyName[j], topo,
102  cfg.EndZCut, tmin, tmax, false/*cfg.DoNegativeReco*/, 0));
103 
104  //Get Variations
105  for (size_t k = 0; k < cfg.SystToConsider.size(); ++k) {
106  std::cout << "Considering " << cfg.SystToConsider[k] << std::endl;
107  for (auto const m : {-1, 1}) {
108  bg_syst_hists.push_back(
110  cfg.MCFileNames[i], cfg.RecoTreeName, cfg.RecoBinning,
111  cfg.ChannelNames[i], cfg.BackgroundTopologyName[j], topo,
112  cfg.EndZCut, tmin, tmax, false/*cfg.DoNegativeReco*/,
113  /*doSyst=*/m, /*systName=*/cfg.SystToConsider[k]));
114 
115  //Turn into frac errors
116  makeFracErrorHist(bg_syst_hists.back(), bg_nom_hists.back());
117  }
118  }
119  }
120 
121  //Signals
122  for (size_t j = 0; j < cfg.SignalTopology.size(); ++j) {
123  int topo = cfg.SignalTopology[j];
124  for (size_t k = 1; k < cfg.TruthBinning.size(); ++k) {
125 
126  //Get Nominal
127  sig_nom_hists.push_back(
129  cfg.MCFileNames[i], cfg.RecoTreeName, cfg.RecoBinning,
130  cfg.ChannelNames[i], cfg.SignalTopologyName[j], topo,
131  cfg.TruthBinning[k-1], cfg.TruthBinning[k], cfg.EndZCut,
132  false/*cfg.DoNegativeReco*/));
133 
134  //Get Variations
135  for (size_t m = 0; m < cfg.SystToConsider.size(); ++m) {
136  for (auto const n : {-1, 1}) {
137  std::cout << "Considering " << cfg.SystToConsider[m] << std::endl;
138  sig_syst_hists.push_back(
140  cfg.MCFileNames[i], cfg.RecoTreeName, cfg.RecoBinning,
141  cfg.ChannelNames[i], cfg.SignalTopologyName[j], topo,
142  cfg.TruthBinning[k-1], cfg.TruthBinning[k], cfg.EndZCut,
143  false/*cfg.DoNegativeReco*/,
144  /*doSyst=*/n, /*systName=*/cfg.SystToConsider[m]));
145 
146  //Turn into frac errors
147  makeFracErrorHist(sig_syst_hists.back(), sig_nom_hists.back());
148  }
149  }
150  }
151  }
152 
153  }
154 
155  //Incident
156  for (size_t j = 0; j < cfg.IncidentTopology.size(); ++j) {
157  //Form nominal
158  TH1 * temp_hist =
160  cfg.IncidentMCFileNames[0], cfg.RecoTreeName, cfg.RecoBinning,
161  /*cfg.ChannelNames[0],*/ cfg.IncidentTopologyName[j], cfg.IncidentTopology[j],
162  0., 10000., cfg.EndZCut, false);
163  for (size_t k = 1; k < cfg.IncidentMCFileNames.size(); ++k) {
164  std::cout << "Trying " << k << std::endl;
165  temp_hist->Add(
167  cfg.IncidentMCFileNames[k], cfg.RecoTreeName, cfg.RecoBinning,
168  /*cfg.ChannelNames[k],*/ cfg.IncidentTopologyName[j], cfg.IncidentTopology[j],
169  0., 10000., cfg.EndZCut, false));
170  }
171  inc_nom_hists.push_back(temp_hist);
172 
173  //GetVariations
174  for (size_t m = 0; m < cfg.SystToConsider.size(); ++m) {
175  for (auto const n : {-1, 1}) {
176  std::cout << "Considering " << cfg.SystToConsider[m] << std::endl;
177 
178  TH1 * temp_hist =
180  cfg.IncidentMCFileNames[0], cfg.RecoTreeName, cfg.RecoBinning,
181  /*cfg.ChannelNames[0],*/ cfg.IncidentTopologyName[j], cfg.IncidentTopology[j],
182  0., 10000., cfg.EndZCut, false, n, cfg.SystToConsider[m]);
183  for (size_t k = 1; k < cfg.IncidentMCFileNames.size(); ++k) {
184  temp_hist->Add(
186  cfg.IncidentMCFileNames[k], cfg.RecoTreeName, cfg.RecoBinning,
187  /*cfg.ChannelNames[k],*/ cfg.IncidentTopologyName[j], cfg.IncidentTopology[j],
188  0., 10000., cfg.EndZCut, false, n, cfg.SystToConsider[m]));
189  }
190  inc_syst_hists.push_back(temp_hist);
191 
192  //Turn into frac errors
193  makeFracErrorHist(inc_syst_hists.back(), inc_nom_hists.back());
194  }
195  }
196  }
197 
198 
199 
200 
201 
202  TFile output(output_file_name.c_str(), "RECREATE");
203  output.cd();
204  saveHists(bg_syst_hists/*, cfg.SystToConsider*/);
205  saveHists(sig_syst_hists/*, cfg.SystToConsider*/);
206  saveHists(inc_syst_hists);
207  output.Close();
208  return 0;
209 }
TH1 * FillMCIncidentHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string topo, int toponum, double reco_beam_endZ_cut, double minval=0., double maxval=100000., bool doNegativeReco=false, int doSyst=0, std::string systName="", double weight=1.0, std::pair< double, double > PiMuScale={1., 1.})
std::string fcl_file_name
TH1 * FillMCBackgroundHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string channel, std::string topo, int toponum, double endZ_cut, double minval=0.0, double maxval=100000.0, bool doNegativeReco=false, int doSyst=0, std::string systName="", double weight=1.0, std::pair< double, double > PiMuScale={1., 1.})
fhicl::ParameterSet makeParameterSet(std::string file)
bool parseArgs(int argc, char **argv)
void saveHists(std::vector< TH1 * > &vec)
std::void_t< T > n
std::string output_file_name
void makeFracErrorHist(TH1 *variation, TH1 *nominal)
TH1 * FillMCSignalHistogram_Pions(std::string filename, std::string treename, std::vector< double > recoBins, std::string channel, std::string topo, int toponum, double minval, double maxval, double endZ_cut, bool doNegativeReco=false, int doSyst=0, std::string systName="", double weight=1.0, std::pair< double, double > PiMuScale={1., 1.})
QTextStream & endl(QTextStream &s)
void makeFracErrorHist ( TH1 *  variation,
TH1 *  nominal 
)

Definition at line 219 of file Geant4ReweightSysts.cc.

219  {
220  // Scale by -1 to subtract
221  nominal->Scale(-1.);
222 
223  // Subtract from var
224  variation->Add(nominal);
225 
226  // Scale back to normal
227  nominal->Scale(-1.);
228 
229  // Divide to get fractional error
230  variation->Divide(nominal);
231 }
fhicl::ParameterSet makeParameterSet ( std::string  file)

Definition at line 268 of file Geant4ReweightSysts.cc.

268  {
269  fhicl::ParameterSet pset;
270 
271  // Configuration file lookup policy.
272  char const* fhicl_env = getenv("FHICL_FILE_PATH");
273  std::string search_path;
274 
275  if (fhicl_env == nullptr) {
276  std::cerr << "Expected environment variable FHICL_FILE_PATH is missing" <<
277  " or empty: using \".\"\n";
278  search_path = ".";
279  }
280  else {
281  search_path = std::string{fhicl_env};
282  }
283 
284  cet::filepath_first_absolute_or_lookup_with_dot lookupPolicy{search_path};
285  return fhicl::ParameterSet::make(file, lookupPolicy);
286 }
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
std::string getenv(std::string const &name)
Definition: getenv.cc:15
bool parseArgs ( int  argc,
char **  argv 
)

Definition at line 233 of file Geant4ReweightSysts.cc.

233  {
234 
235  bool found_fcl_file = false;
236  bool found_output_file = false;
237 
238  for (int i = 1; i < argc; ++i) {
239  if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)) {
240  std::cout << "Usage: ./Geant4ReweightSysts -c <fitter_config>.fcl " <<
241  " -o <output_file>.root" << std::endl;
242  std::cout << std::endl;
243 
244  return false;
245  }
246 
247  else if (strcmp(argv[i], "-c") == 0) {
248  fcl_file_name = argv[i+1];
249  found_fcl_file = true;
250  }
251 
252  else if (strcmp(argv[i], "-o") == 0) {
253  output_file_name = argv[i+1];
254  found_output_file = true;
255  }
256 
257  }
258 
259  if (!found_fcl_file || !found_output_file) {
260  std::cout << "Error: Must provide fcl file with options '-c' and '-o'" <<
261  std::endl;
262  return false;
263  }
264 
265  return true;
266 }
std::string fcl_file_name
std::string output_file_name
int strcmp(const String &s1, const String &s2)
Definition: relates.cpp:14
QTextStream & endl(QTextStream &s)
void saveHists ( std::vector< TH1 * > &  vec)

Definition at line 211 of file Geant4ReweightSysts.cc.

211  {
212  for (auto * h : vec) {
213  //std::string name = h->GetName();
214  //h->SetName((name + "_" + addToName).c_str());
215  h->Write(/*(name + "_" + addToName).c_str()*/);
216  }
217 }

Variable Documentation

std::string fcl_file_name

Definition at line 16 of file Geant4ReweightSysts.cc.

std::string output_file_name

Definition at line 15 of file Geant4ReweightSysts.cc.