MakeCosmicSpectra.C
Go to the documentation of this file.
1 /// MakeCosmicSpectra.C by J. Hewes (jhewes15@fnal.gov)
2 
3 #include "CAFAna/Core/Spectrum.h"
7 
9 
10 #include "TFile.h"
11 
12 using namespace ana;
13 
14 using std::cout;
15 using std::endl;
16 using std::exception;
17 using std::ostringstream;
18 using std::runtime_error;
19 
20 using covmx::Sample;
21 
22 void MakeCosmicSpectra(TString opt, double res=0) {
23 
24  try {
25  DontAddDirectory guard;
26  Sample sample = GetSampleFromOptString(opt);
27  SetAxis(sample, res);
28  SetCut(sample);
29 
30  ostringstream loaderName;
31  loaderName << "prod_sumdecaf_R19-11-18-prod5reco.i_fd_cosmic_";
32  if (sample.polarity == covmx::kFHC) loaderName << "fhc";
33  else loaderName << "rhc";
34  loaderName << "_full_v1_goodruns_";
35  if (sample.selection == covmx::kNC) {
36  if (sample.polarity == covmx::kFHC) loaderName.str("prod_caf_R19-11-18-prod5reco.i_fd_cosmic_fhc_full_v1_goodruns");
37  else loaderName.str("prod_caf_R19-11-18-prod5reco.i_fd_cosmic_rhc_full_v1_goodruns");
38  }
39  else if (sample.selection == covmx::kCCNumu) loaderName << "numu2020";
40  else if (sample.selection == covmx::kCCNue) loaderName << "nue2020";
41  else throw runtime_error("Sample selection not recognised! Exiting.");
42 
43  SpectrumLoader loader(loaderName.str());
44  loader.SetSpillCut(kStandardSpillCuts);
45  const Cut cut = *sample.GetCut() && kInCosmicTimingWindow;
46  Spectrum spec(loader, *sample.GetAxis(), cut);
47 
48  loader.Go();
49 
50  ostringstream outFileName;
51  outFileName << "cosmic_" << sample.GetTag();
52  if (res != 0) outFileName << "_" << (int)res;
53  outFileName << ".root";
54  TFile* outFile = TFile::Open(outFileName.str().c_str(), "recreate");
55  spec.SaveTo(outFile->mkdir(sample.GetTag().c_str()));
56  delete outFile;
57 
58  } catch(const exception& e) {
59  cout << endl << "Exception occurred! " << e.what() << endl;
60  }
61 
62 } // macro MakeCosmicSpectra
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void SetCut(covmx::Sample &sample)
Definition: Utilities.h:274
covmx::Sample GetSampleFromOptString(TString optString)
Function to take an option TString and return a single associated covmx::Sample.
Definition: Utilities.h:355
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
void SetAxis(TH1 *h, bool visible, int color, int style=1, bool scale=true)
const Cut kInCosmicTimingWindow
Is the event far from the start and ends of the spill ? For FD cosmic selection.
Definition: TimingCuts.cxx:165
TFile * outFile
Definition: PlotXSec.C:135
loader
Definition: demo0.py:10
OStream cout
Definition: OStream.cxx:6
const Cut cut
Definition: exporter_fd.C:30
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
void MakeCosmicSpectra(TString opt, double res=0)
Prevent histograms being added to the current directory.
Definition: UtilsExt.h:46
Float_t e
Definition: plot.C:35