DataVtxDistributionLoad.C
Go to the documentation of this file.
1 // This macro creates spectra for OBSERVED
2 // and predicted event rates in analysis region
3 // This uses UNBLIND DATA. Proceed with extreme caution!
4 
8 #include "NuXAna/Cuts/NusCuts.h"
10 #include "CAFAna/Cuts/TimingCuts.h"
12 #include "CAFAna/Extrap/ExtrapSterile.h"
16 #include "CAFAna/Vars/HistAxes.h"
19 
20 #include <string>
21 #include <utility>
22 
23 using namespace ana;
24 
26 {
27  TH1::AddDirectory(0);
28 
29  // FD DATA
31  loaderFDdata.SetSpillCut(kStandardSpillCuts);
32 
33  std::string labelVtxX = "X Vertex Position (cm)";
34  std::string labelVtxY = "Y Vertex Position (cm)";
35  std::string labelVtxZ = "Z Vertex Position (cm)";
36 
37  Binning kXYBinsFD = Binning::Simple(320, -800., 800.);
38  Binning kZBinsFD = Binning::Simple(1200, 0., 6000.);
39 
40  const Var kRecoVtxX(
41  [](const caf::SRProxy* sr)
42  {
43  if( !sr->vtx.elastic.IsValid) { return 9000.; }
44  return sr->vtx.elastic.vtx.x;
45  });
46  const Var kRecoVtxY(
47  [](const caf::SRProxy* sr)
48  {
49  if(!sr->vtx.elastic.IsValid) { return 9000.; }
50  return sr->vtx.elastic.vtx.y;
51  });
52  const Var kRecoVtxZ(
53  [](const caf::SRProxy* sr)
54  {
55  if(!sr->vtx.elastic.IsValid) { return 9000.; }
56  return sr->vtx.elastic.vtx.z;
57  });
58 
59  const HistAxis kAxisVtxX(labelVtxX, kXYBinsFD, kRecoVtxX);
60  const HistAxis kAxisVtxY(labelVtxY, kXYBinsFD, kRecoVtxY);
61  const HistAxis kAxisVtxZ(labelVtxZ, kZBinsFD, kRecoVtxZ);
62 
63  // set up the cuts map
64  std::map<std::string, Cut*> cuts;
65  cuts["All"] = new Cut(kNusFD);
66 
67  std::map<std::string, Spectrum*> sXYs;
68  std::map<std::string, Spectrum*> sXZs;
69  std::map<std::string, Spectrum*> sYZs;
70 
71  for(const auto& strcut : cuts) {
72  std::string label = strcut.first;
73 
74  sXYs[label] = new Spectrum(loaderFDdata, kAxisVtxX, kAxisVtxY, kInBeamSpill && *strcut.second);
75  sXZs[label] = new Spectrum(loaderFDdata, kAxisVtxZ, kAxisVtxX, kInBeamSpill && *strcut.second);
76  sYZs[label] = new Spectrum(loaderFDdata, kAxisVtxZ, kAxisVtxY, kInBeamSpill && *strcut.second);
77  }
78 
79  // Fill the spectra!
80  loaderFDdata.Go();
81 
82  // Set up output filename
83  TFile* rootF = new TFile(outfile.c_str(), "RECREATE");
84 
85  // Save all of the objects
86  TDirectory* tmp = gDirectory;
87  TDirectory* saveDir = gDirectory;
89  std::string sep = "__";
90 
91  for(const auto& strcut : cuts) {
92  std::string label = strcut.first;
93 
94  dir = "sXY" + sep + label;
95  saveDir = rootF->mkdir(dir.c_str());
96  sXYs[label]->SaveTo(saveDir);
97 
98  dir = "sXZ" + sep + label;
99  saveDir = rootF->mkdir(dir.c_str());
100  sXZs[label]->SaveTo(saveDir);
101 
102  dir = "sYZ" + sep + label;
103  saveDir = rootF->mkdir(dir.c_str());
104  sYZs[label]->SaveTo(saveDir);
105  }
106 
107  tmp->cd();
108  rootF->Close(); // Close the file
109 }
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 Cut kNusFD
Definition: NusCuts.h:46
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2085
Float_t tmp
Definition: plot.C:36
void SetSpillCut(const SpillCut &cut)
const char * label
caf::Proxy< caf::SRElastic > elastic
Definition: SRProxy.h:2077
const Binning kXYBinsFD
caf::Proxy< float > z
Definition: SRProxy.h:107
const Binning kZBinsFD
caf::Proxy< float > x
Definition: SRProxy.h:105
_Cut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
std::vector< float > Spectrum
Definition: Constants.h:570
const char sep
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void DataVtxDistributionLoad(std::string outfile)
caf::Proxy< bool > IsValid
Definition: SRProxy.h:2017
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
caf::Proxy< float > y
Definition: SRProxy.h:106
TDirectory * dir
Definition: macro.C:5
caf::Proxy< caf::SRVector3D > vtx
Definition: SRProxy.h:2032
const Cut kInBeamSpill([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return kInBeamSpill_main(sr);else return kInBeamSpill_main(sr)||kInBeamSpill_shifted(sr);}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return kInBeamSpill_main.Livetime(spill);else return kInBeamSpill_main.Livetime(spill)+kInBeamSpill_shifted.Livetime(spill);}, [](const caf::SRSpillProxy *spill) -> double{return spill->spillpot;})
Does the event fall inside the window we call the beam spill?
Definition: TimingCuts.h:8
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2105
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:114
FILE * outfile
Definition: dump_event.C:13
const std::vector< std::string > fnamefardata_unblind(MakeUnblindList())