generate_fd_fake_events.C
Go to the documentation of this file.
1 /// \file generate_fd_fake_events.C
2 /// \brief Produce fake FD files (but including the real 2018 data)
3 /// to aid in testing blessed plots before box opening
4 /// \author J. Wolcott <jwolcott@fnal.gov>
5 /// \date Mar. 21, 2019
6 
7 #include <numeric>
8 #include <deque>
9 
10 #include "TRandom3.h"
11 #include "TTree.h"
12 
16 #include "CAFAna/Core/Utilities.h"
17 #include "CAFAna/Cuts/SpillCuts.h"
20 #include "OscLib/OscCalcPMNSOpt.h"
21 #include "StandardRecord/SRSpill.h"
25 
26 #include "fake_data.h"
27 
28 using namespace ana;
29 
30 namespace ana2019
31 {
32  // amount of livetime (in seconds) assumed for each spill.
33  // lifted from TimingCuts.cxx
35 
36  // lifted from R18-02-25-art1.a/CAFAna/nue/reduce_nue_rhc.C (2018 decaf macro)
37  const Var kCVN2017e([](const caf::SRProxy* sr){return sr->sel.cvn.nueid;});
39 
40  namespace fakedata
41  {
42  const std::string OUT_FILE_STUB = "fake_fd_events_2019_%s.root";
43 
44  /// base class: random number generator with easily settable seed...
45  class EvtHashRNG
46  {
47  public:
49  : fRng(0)
50  {}
51 
52  TRandom * RNG() { return &fRng; }
53  void SetSeed(std::size_t seed) { fRng.SetSeed(seed); }
54 
55  private:
56  mutable TRandom3 fRng;
57  };
58 
59  /// Class for deciding whether to keep an event (either full StandardRecord or just SRSpill)
60  /// based on a random number generator and a single (changable) probability
61  class KeepEvtFunc : public EvtHashRNG
62  {
63  public:
64  KeepEvtFunc(double keepProb)
65  : fKeepProb(keepProb), fLastHash(0)
66  {}
67 
68  virtual bool Keep(const caf::SRSpillProxy *sr)
69  {
70  return Keep(Hash(sr));
71  }
72 
73  virtual bool Keep(const caf::SRProxy *sr)
74  {
75  auto hash = Hash({Hash(&sr->spill), (std::size_t)(sr->hdr.cycle), sr->hdr.subevt});
76  return Keep(hash);
77  }
78 
79  void SetKeepProb(double prob)
80  {
81  fKeepProb = prob;
82  }
83 
84  protected:
85 
86  bool Keep(std::size_t hash)
87  {
88  if (hash != fLastHash)
89  {
90  SetSeed(hash);
91  fLastHash = hash;
92  }
93 
94  return RNG()->Uniform() < fKeepProb;
95  }
96 
97  private:
98  double fKeepProb;
99  mutable std::size_t fLastHash;
100  };
101 
102  /// Functional for deciding whether to keep an MC event
103  /// based on a fixed probability (e.g., POT-based)
104  /// and on oscillation probability.
105  /// Can be passed to a CAFAna Cut object as its internal function
107  {
108  public:
109  /// 'keepProb' is for all events (depends on POT only).
110  /// 'NCwgt' is because we get NCs from all the swap files too
111  /// and have too many unless we weight them down...
112  /// you can pass in 'kept' in case you want to know what kind of events were retained...
113  KeepMCEventFunc(double keepProb, double NCwgt, std::map<std::pair<int, int>, unsigned int> * kept = nullptr)
114  : KeepEvtFunc(keepProb), fNCwgt(NCwgt), fEventsKept(kept)
115  {
116  ResetOscCalcToDefault(&fCalc);
117  }
118 
119 
120  bool operator()(const caf::SRProxy * sr)
121  {
122  // short-circuit on the POT prob to avoid doing oscillation prob calculations unnecessarily
123  if (!Keep(&sr->spill))
124  return false;
125 
126  if (sr->mc.nnu != 1)
127  return false;
128 
129  bool keep;
130  if (sr->mc.nu[0].iscc)
131  keep = RNG()->Uniform() < fCalc.P(sr->mc.nu[0].pdgorig, sr->mc.nu[0].pdg, sr->mc.nu[0].E);
132  else
133  keep = RNG()->Uniform() < fNCwgt;
134 
135  if (keep && fEventsKept)
136  {
137  auto flav = sr->mc.nu[0].iscc ? (std::make_pair(sr->mc.nu[0].pdgorig, sr->mc.nu[0].pdg))
138  : (std::make_pair(0, 0));
139  (*fEventsKept)[flav]++;
140  }
141  return keep;
142  }
143 
144  auto EventsKept() const
145  {
146  return fEventsKept;
147  }
148 
149  private:
150  double fNCwgt;
152 
153  mutable std::map<std::pair<int, int>, unsigned int> * fEventsKept;
154  };
155  } // namespace fakedata
156 
157  /// a very dumb implementation of a stream-wrapper that makes the text in one sequence of <<s some color and resets afterwards.
158  /// helps output stick out since the SpectrumLoaders are fairly chatty in between useful output.
159  /// resets the stream when it's destroyed so that subsequent text doesn't show up with color.
160  /// use like:
161  /// ColorStream(std::cout) << "This text, and this number " << 5736 << " show up as cyan!" << std::endl;
162  /// ColorStream(std::cout, 31) << "This text is red!" << std::endl;
163  /// std::cout << "This text has no special coloring" << std::endl;
165  {
166  public:
167  ColorStream(std::ostream & os, unsigned int col=36)
168  : fOS(os)
169  {
170  // printf so that it definitely all goes into the same stream with no flushes in between
171  printf("\033[%d;1m", col);
172  }
174  {
175  fOS << "\033[0;0m";
176  }
177 
178  template <typename T>
179  std::ostream & operator<<(const T & t)
180  {
181  return fOS << t;
182  }
183 
184  private:
185  std::ostream & fOS;
186  };
187 } // namespace ana2019
188 
189 // -------------------------------------------------
190 
192 {
193  // ------------ step 0:
194  // which sample are we working with?
195  std::string fdDataDef;
196  const Cut * decafCut;
197  ECAFType decafType;
198  if (sample == "nue")
199  {
200  decafType = kNueConcat;
201  decafCut = &ana2019::kNueFD2018DecafCut;
202  fdDataDef = "prod4_sumrestricteddecaf_fd_numi_rhc_full_goodruns_nue2018";
203  }
204  else if (sample == "numu")
205  {
206  decafType = kNumuConcat;
207  decafCut = &kNumuDecafCutFD2018;
208  fdDataDef = "prod4_sumrestricteddecaf_fd_numi_rhc_full_goodruns_numu2018";
209  }
210  else
211  {
212  std::cerr << "Unknown sample: '" << sample << "'" << std::endl;
213  std::cerr << "I only know how to make fake data for 'numu' or 'nue' samples." << std::endl;
214  return;
215  }
216 
217  // ------------ step 1:
218  // figure out how much POT and livetime we already have,
219  // both in RHC data and the MC sample we'll be drawing from
220  ana2019::ColorStream(ana2019::ColorStream(std::cout)) << "Counting POT in RHC MC and data datasets..." << std::endl << std::endl;
221 
222  const std::map<Loaders::SwappingConfig, std::string> kSwaps
223  {
224  {Loaders::kNonSwap, "nonswap"},
225  {Loaders::kFluxSwap, "fluxswap"},
226  {Loaders::kTauSwap, "tauswap"}
227  };
228 
230  // the loaders don't normally know where the FD data is to prevent accidental unblinding.
231  // but, since these fake events are meant to include the FD events
232  // we've already selected in 2018, we need to make an exception.
233  loaders.SetLoaderPath(fdDataDef, caf::kFARDET, Loaders::kData);
234 
236  HistAxis dummyAxis("dummy", Binning::Simple(1, 0, 1), kUnweighted);
237  std::map<Loaders::SwappingConfig, Spectrum> mcDummySpecs;
238  std::map<Loaders::SwappingConfig, TH1D> mcDummySpillHists;
239  for (const auto swapPair : kSwaps)
240  {
241  auto & loader = loaders.GetLoader(caf::kFARDET, Loaders::kMC, kBeam, swapPair.first);
242  mcDummySpecs.emplace(std::piecewise_construct,
243  std::forward_as_tuple(swapPair.first),
244  std::forward_as_tuple(loader, dummyAxis, *decafCut));
245  mcDummySpillHists.emplace(std::piecewise_construct,
246  std::forward_as_tuple(swapPair.first),
247  std::forward_as_tuple(Form("spills_%d", swapPair.first), "", 1, 0, 2));
248  loader.AddSpillHistogram(&mcDummySpillHists.at(swapPair.first), kSpillUnweighted, kStandardSpillCuts);
249  }
250  Spectrum dataDummySpec(loaders.GetLoader(caf::kFARDET, Loaders::kData), dummyAxis, *decafCut && kInBeamSpill);
251 
252  loaders.Go();
253 
254  // ------------ step 2:
255  // draw events out of the MC according to the expected rates
256  // (using the 2018 best fit oscillation parameters
257  // and the ratio of the desired "new data" and MC exposures).
258  // simultaneously rewrite the MC spill records to match the "new data" POT & livetime
259  const double fakeDataPOT = ana2019::fakedata::FULL_RHC_EXPOSURE - dataDummySpec.POT();
260  const double fakeDataLivetime = fakeDataPOT / dataDummySpec.POT() * dataDummySpec.Livetime();
261  double totalMCPOT = 0;
262  for (const auto & swapPair : mcDummySpecs)
263  totalMCPOT += swapPair.second.POT();
264 
265  ana2019::ColorStream(std::cout) << "Found the following POT:" << std::endl;
266  ana2019::ColorStream(std::cout) << " data --> " << dataDummySpec.POT() << std::endl;
268  << " total RHC POT, we need to draw " << fakeDataPOT << " POT of fake data.)" << std::endl;
269  for (const auto & swapPair : mcDummySpecs)
270  ana2019::ColorStream(std::cout) << " MC swap " << swapPair.first << " --> " << swapPair.second.POT()
271  << " (" << mcDummySpillHists.at(swapPair.first).Integral() << " spills)" << std::endl;
272  ana2019::ColorStream(std::cout) << " --> total MC = " << totalMCPOT << std::endl;
273  ana2019::ColorStream(std::cout) << "Found data livetime = " << dataDummySpec.Livetime() << "s" << std::endl;
274  ana2019::ColorStream(std::cout) << " so when scaled to " << ana2019::fakedata::FULL_RHC_EXPOSURE << " POT equivalent,"
275  << " need " << fakeDataLivetime << "s of livetime in fake data." << std::endl;
276 
277 
278  std::map<Loaders::SwappingConfig, std::string> intermediateFileNames;
279  const double MCSwapScale = 1. / mcDummySpecs.size(); // so that we only count the NCs & the POT once over all the swaps...
280  for (const auto & swapPair : mcDummySpecs)
281  {
282  auto swap = swapPair.first;
283 
284  // a further complication here.
285  // we need to keep the full "fake data"'s worth of POT for the CC events,
286  // since each possible oscillation pair (nue -> nue, nue -> numu, nue -> nutau, numu -> nue, ...)
287  // is represented only once over the various swaps.
288  // however, there are NCs in all of them,
289  // and we also want to keep only enough spill records from all the swaps
290  // to add to the total desired fake data POT,
291  // so both NC events & spill records are reduced by the extra MCSwapScale from above.
292  double keepProbCC = fakeDataPOT / swapPair.second.POT();
293  const auto nSpills = mcDummySpillHists.at(swapPair.first).Integral();
294  const double keepProbSpill = (fakeDataLivetime * MCSwapScale) / ana2019::kFixedSpillLivetime / nSpills;
295  if (keepProbSpill < 0 || keepProbSpill > 1)
296  {
297  ana2019::ColorStream(std::cout, 31) << "Error: spill retention probability is invalid: " << keepProbSpill
298  << std::endl;
299  ana2019::ColorStream(std::cout, 31) << "Perhaps you have too few spills (" << nSpills << ") to add up to the necessary livetime"
300  << " (note that they are " << ana2019::kFixedSpillLivetime << "s/spill)?" << std::endl;
301  abort();
302  }
303  std::cout << std::endl;
304  ana2019::ColorStream(std::cout) << "---------------" << std::endl;
305  std::cout << std::endl;
306  ana2019::ColorStream(std::cout) << "For swap " << swap << ":" << std::endl;
307  ana2019::ColorStream(std::cout) << " acceptance probability for CC events: " << keepProbCC << std::endl;
308  ana2019::ColorStream(std::cout) << " (for spill info & NC events, this is further modified by a factor of " << MCSwapScale
309  << " since we will be sampling from multiple swaps.)" << std::endl;
310  ana2019::ColorStream(std::cout) << " N spills = " << nSpills << std::endl;
311  ana2019::ColorStream(std::cout) << " need to retain " << (fakeDataLivetime * MCSwapScale) / ana2019::kFixedSpillLivetime
312  << " spills to get desired livetime" << std::endl;
313 
314  std::string intermediateFileName = "2019fakedata.intermediate-" + kSwaps.at(swap) + ".root";
315  intermediateFileNames[swap] = intermediateFileName;
316 
317  std::map<std::pair<int, int>, unsigned int> eventsKept;
318  // the second argument is the further reduction factor applied to NC events mentioned above
319  ana2019::fakedata::KeepMCEventFunc keepMcEventFunc {keepProbCC, MCSwapScale, &eventsKept};
320  Cut kKeepEventCut{keepMcEventFunc};
321  // for spill records we need to scale down as mentioned above
322  ana2019::fakedata::KeepEvtFunc keepSpillFuncObj{keepProbCC * MCSwapScale};
323  FileReducer MCsampler(loaders.GetLoaderPath(caf::kFARDET, Loaders::kMC, kBeam, swap), intermediateFileName);
324  MCsampler.AddEventCut(kKeepEventCut);
325  MCsampler.AddEventCut(*decafCut);
326  double totalPOT = 0;
327  double totalLive = 0;
328  // todo: it would be *better* for this to be a _cut_ on the spill, but FileReducer has no such concept.
329  // instead we just reset those spills that were rejected and count on ROOT compression to shrink them down
330  MCsampler.AddSpillReductionStep([&](caf::SRSpill *spill, const caf::SRSpillProxy *spillProxy)
331  {
332  bool potKeep = false;
333  if (spill->isgoodspill && spill->spillpot > 0)
334  {
335  keepSpillFuncObj.SetKeepProb(keepProbCC * MCSwapScale);
336  potKeep = keepSpillFuncObj.Keep(spillProxy);
337  }
338 
339  // always keep a spill for livetime if we're keeping it for POT
340  keepSpillFuncObj.SetKeepProb(keepProbSpill);
341  bool livetimeKeep = potKeep || keepSpillFuncObj.Keep(spillProxy);
342 
343  if (potKeep)
344  totalPOT += spillProxy->spillpot;
345  else
346  spill->spillpot = 0;
347 
348  if (livetimeKeep)
349  {
350  // MC livetimes are meaningless because we don't simulate all the cosmics-only spills
351  // where most of the livetime is anyway.
352  // so even though we override the livetime *amount* here for completeness,
353  // the thing that actually makes the difference is that
354  // we are keeping the right *number* of spill.isgoodspill==true
355  // entries in the tree
357  totalLive += ana2019::kFixedSpillLivetime;
358  }
359 
360  if (!potKeep && !livetimeKeep)
361  {
362  // just reset the whole thing
363  *spill = caf::SRSpill();
364 
365  // make sure no NaNs
366  spill->spillpot = 0;
367  spill->livetime = 0;
368  }
369 
370  // no matter what, we need to treat this as a "data" spill
371  // so that either its livetime is counted correctly
372  // or so that it's disregarded
373  spill->ismc = false;
374  });
375 
376  MCsampler.Go();
377 
378  // update the POT, livetime, and event counts in the file, which are otherwise lying
379  TFile fakeEventsFile(intermediateFileName.c_str(), "update");
380  auto potHist = dynamic_cast<TH1 *>(fakeEventsFile.Get("TotalPOT"));
381  potHist->SetBinContent(1, totalPOT);
382  potHist->Write();
383  auto liveHist = dynamic_cast<TH1 *>(fakeEventsFile.Get("TotalLivetime"));
384  liveHist->SetBinContent(1, totalLive);
385  liveHist->Write();
386 
387  auto evtTree = dynamic_cast<TTree *>(fakeEventsFile.Get("recTree"));
388  auto evtHist = dynamic_cast<TH1 *>(fakeEventsFile.Get("TotalEvents"));
389  std::size_t evts = evtTree->GetEntries();
390  evtHist->SetBinContent(1, evts);
391  evtHist->Write();
392  fakeEventsFile.Close();
393 
394  std::cout << std::endl;
395  ana2019::ColorStream(std::cout) << " Drew " << totalPOT << " POT, which is " << (100 * totalPOT / (fakeDataPOT * MCSwapScale))
396  << "% of the desired amount." << std::endl;
397  ana2019::ColorStream(std::cout) << " " << evts << " new events were sampled from the MC:" << std::endl;
398  for (const auto & keptPair : eventsKept)
399  {
400  std::cout << " ";
401  std::pair<int, int> flav = keptPair.first;
402  unsigned int kept = keptPair.second;
403  if (flav.first == 0)
405  else
406  {
408  for (const auto &v : {flav.first, flav.second})
409  {
410  if (std::abs(v) == 12)
411  out += "nue";
412  else if (std::abs(v) == 14)
413  out += "numu";
414  else if (std::abs(v) == 16)
415  out += "nutau";
416  else
417  out += std::to_string(v);
418 
419  if (v < 0)
420  out += "bar";
421 
422  out += " --> ";
423  }
424  out = out.substr(0, out.size() - 5);
426  }
427  ana2019::ColorStream(std::cout) << " = " << kept << std::endl;
428  }
429  }
430 
431 
432  // ------------ step 3:
433  // add the 2018 data events back into the file.
434  // while doing that, also sample cosmics from the timing sideband
435  // and use those as "fake" cosmics by moving them into the beam window...
436  std::vector<std::string> files;
437  std::transform(intermediateFileNames.begin(), intermediateFileNames.end(), std::back_inserter(files),
438  [](const auto & swapFilePair){ return swapFilePair.second; }
439  );
440  SAMQuerySource samquerysource(loaders.GetLoaderPath(caf::kFARDET, Loaders::kData));
441  files.reserve(files.size() + samquerysource.NFiles());
442  files.insert(files.end(), samquerysource.GetFileNames().begin(), samquerysource.GetFileNames().end());
443  FileReducer combiner(files, Form(ana2019::fakedata::OUT_FILE_STUB.c_str(), sample.c_str()));
444 
445  // this is a bit weird.
446  // to get some 'simulated' cosmics, we're going to take the out-of-time cosmics
447  // and, with probability corresponding to the (needed new exposure)/(actual exposure),
448  // **move those events into the beam window**.
449  // we're assuming that the livetime scales exactly with the POT, which won't be right
450  // for the actual new data, but is fine for this fake data.
451  double OOTKeepProb = util::kBeamWindowMicroSec / (util::kMaxTimingSidebandAfterMicroSec - util::kMinTimingSidebandAfterMicroSec);
452  OOTKeepProb *= fakeDataPOT / dataDummySpec.POT(); // note that if the timing sideband were smaller than the beam window, this would result in probabilities > 1
453  assert(OOTKeepProb < 1);
454 
455  ana2019::fakedata::KeepEvtFunc keepCosmicFunc{OOTKeepProb};
456  combiner.AddEventCut(*decafCut);
457  combiner.AddReductionStep([OOTKeepProb, &keepCosmicFunc, &decafCut](caf::StandardRecord * sr, const caf::SRProxy * srp){
458  const auto t = sr->slc.meantime;
459  if (t < 1000*util::kMinTimingSidebandAfterMicroSec || t > 1000*util::kMaxTimingSidebandAfterMicroSec)
460  return;
461 
462  if (!keepCosmicFunc.Keep(srp))
463  return;
464 
465  // are there other branches that need to be adjusted?
466  double newTimeNS = util::kBeamWindowMinMicroSec + keepCosmicFunc.RNG()->Uniform() * (util::kBeamWindowMaxMicroSec - util::kBeamWindowMinMicroSec);
467  newTimeNS *= 1000;
468  std::deque<std::reference_wrapper<float>> toUpdate
469  {
470  sr->slc.meantime,
471  sr->slc.starttime,
472  sr->slc.endtime,
473  };
474  for (auto & vtx : sr->vtx.elastic)
475  toUpdate.push_back(vtx.time);
476 
477  for (auto & val : toUpdate)
478  val += newTimeNS - val; // since aren't reassigning the reference, which is what operator=() would do
479  });
480  combiner.AddEventCut(*decafCut);
481  combiner.Go();
482 
483  for (const auto & fileNamePair : intermediateFileNames)
484  system( ("rm " + fileNamePair.second).c_str() );
485 }
caf::Proxy< caf::SRSpill > spill
Definition: SRProxy.h:2055
Shared items for fake data studies for 2019 analysis.
Far Detector at Ash River.
Definition: SREnums.h:11
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void ResetOscCalcToDefault(osc::IOscCalcAdjustable *calc)
Reset calculator to default assumptions for all parameters.
Definition: Calcs.cxx:23
system("rm -rf microbeam.root")
std::map< std::pair< int, int >, unsigned int > * fEventsKept
const Cut kApplySecondAnalysisMask([](const caf::SRProxy *sr){if(sr->hdr.det!=caf::kFARDET) return true; std::bitset< 14 > binary(sr->hdr.dibmask);std::pair< int, int > planesA=calcFirstLastLivePlane(sr->slc.firstplane, binary);std::pair< int, int > planesB=calcFirstLastLivePlane(sr->slc.lastplane, binary);if((planesA.first!=planesB.first)||(planesA.second!=planesB.second)) return false;return((planesA.second-planesA.first+1)/64 >=4);})
Definition: AnalysisMasks.h:18
const int kBeamWindowMicroSec
How long is the beam window?
const int kBeamWindowMinMicroSec
virtual bool Keep(const caf::SRProxy *sr)
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:2049
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2038
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:570
virtual bool Keep(const caf::SRSpillProxy *sr)
float starttime
start time [ns]
Definition: SRSlice.h:39
const Cut kNueDQ2017CVN([](const caf::SRProxy *sr){if(sr->sel.nuecosrej.hitsperplane >=8) return false;if(!sr->vtx.elastic.IsValid) return false;if(sr->vtx.elastic.fuzzyk.npng==0) return false;return true;})
Definition: NueCuts2017.h:28
OStream cerr
Definition: OStream.cxx:7
caf::Proxy< short int > nnu
Definition: SRProxy.h:569
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
KeepMCEventFunc(double keepProb, double NCwgt, std::map< std::pair< int, int >, unsigned int > *kept=nullptr)
const int kMinTimingSidebandAfterMicroSec
float abs(float number)
Definition: d0nt_math.hpp:39
const int kBeamWindowMaxMicroSec
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:33
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
const SpillVar kSpillUnweighted
Definition: Var.h:102
void AddReductionStep(const std::function< ReductionFunc > &f)
Run the specified reduction function over each event.
Definition: FileReducer.h:85
std::string GetLoaderPath(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap) const
Definition: Loaders.cxx:89
float endtime
end time [ns]
Definition: SRSlice.h:40
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
const double FULL_RHC_EXPOSURE
Definition: fake_data.h:17
caf::Proxy< short unsigned int > subevt
Definition: SRProxy.h:245
unsigned int seed
Definition: runWimpSim.h:102
caf::Proxy< caf::SRCVNResult > cvn
Definition: SRProxy.h:1205
SpectrumLoaderBase & GetLoader(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Retrieve a specific loader.
Definition: Loaders.cxx:129
Int_t col[ntarg]
Definition: Style.C:29
caf::Proxy< float > nueid
Definition: SRProxy.h:858
const double kFixedSpillLivetime
bool isgoodspill
Was the pot for a spill good? (only applicable to data, default true)
Definition: SRSpill.h:32
void AddEventCut(const Cut &cut)
Only copy records to the output file if they pass this cut.
Optimized version of OscCalcPMNS.
Definition: StanTypedefs.h:31
printf("%d Experimental points found\n", nlines)
const Cut kNumuDecafCutFD2018
Definition: NumuCuts2018.h:33
ColorStream(std::ostream &os, unsigned int col=36)
caf::Proxy< int > cycle
Definition: SRProxy.h:225
File source based on a SAM query or dataset (definition)
loader
Definition: demo0.py:10
virtual void Go() override
Load all the registered spectra.
const Var kCVNSSe([](const caf::SRProxy *sr){throw std::runtime_error("kCVNSSe is no longer available. Fix your macro so you don't use it.");return-5.;})
2018 nue PID
Definition: Vars.h:52
Create smaller CAFs.
Definition: FileReducer.h:56
OStream cout
Definition: OStream.cxx:6
float livetime
Length of readout [s].
Definition: SRSpill.h:40
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2050
bool operator()(const caf::SRProxy *sr)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
The StandardRecord is the primary top-level object in the Common Analysis File trees.
std::size_t Hash(const std::vector< std::size_t > &vals)
Generate a unique hash from a sequence of integers.
Definition: Utilities.cxx:651
const std::string OUT_FILE_STUB
std::vector< Loaders * > loaders
Definition: syst_header.h:386
SRElastic elastic
Single vertex found by Elastic Arms.
void generate_fd_fake_events(const std::string &sample)
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
assert(nhit_max >=nhit_nbins)
SRSlice slc
Slice branch: nhit, extents, time, etc.
std::ostream & operator<<(const T &t)
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:46
float spillpot
Definition: SRSpill.h:38
double T
Definition: Xdiff_gwt.C:5
base class: random number generator with easily settable seed...
caf::Proxy< caf::SRIDBranch > sel
Definition: SRProxy.h:2053
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
For nominal spectra and reweighting systs (xsec/flux)
Definition: Prod4Loaders.h:96
Float_t e
Definition: plot.C:35
void SetLoaderPath(const std::string &path, caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Configure loader via wildcard path.
Definition: Loaders.cxx:25
const Cut kNueFD2018DecafCut
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:38
bool ismc
data or MC? True if MC
Definition: SRSpill.h:30
const Var kCVN2017e([](const caf::SRProxy *sr){return sr->sel.cvn.nueid;})
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:100
static constexpr Double_t sr
Definition: Munits.h:164
float meantime
mean time, weighted by charge [ns]
Definition: SRSlice.h:41
SRVertexBranch vtx
Vertex branch: location, time, etc.
ECAFType
Definition: Loaders.h:19
const int kMaxTimingSidebandAfterMicroSec