11 #include "sbnanaobj/StandardRecord/Proxy/SRProxy.h"
63 return a.
ID() < b.
ID();
71 std::cerr <<
"Error: can only call Go() once on a SpectrumLoader" << std::endl;
87 const int Nfiles =
NFiles();
91 caf::SRBranchRegistry::clear();
97 if(Nfiles >= 0 && !prog) prog =
new Progress(TString::Format(
"Filling %lu spectra from %d files matching '%s'",
fHistDefs.TotalSize(), Nfiles,
fWildcard.c_str()).
Data());
101 if(Nfiles > 1 && prog) prog->
SetProgress((fileIdx+1.)/Nfiles);
118 assert(!f->IsZombie());
120 TTree* tr = (TTree*)f->Get(
"recTree");
127 const bool has_husk = tr->GetLeaf(
"rec.hdr.husk");
133 long Nentries = tr->GetEntries();
136 for(
long n = 0;
n < Nentries; ++
n){
140 if(!has_husk) sr.hdr.husk =
false;
155 inline T
Get(
const U& var,
const V* sr)
157 const unsigned int id = var.ID();
163 const T val = var(sr);
179 if(sr->hdr.first_in_subrun){
184 if(sr->hdr.ismc)
fNReadouts += sr->hdr.ngenevt;
188 const int nbnb = sr->hdr.bnbinfo.size();
189 const int nnumi = sr->hdr.numiinfo.size();
190 if(nbnb > 0 && nnumi > 0){
191 std::cout <<
"SpectrumLoader: nonzero number of both BNB (" << nbnb
192 <<
") and NuMI (" << nnumi <<
") triggers. I'm confused"
202 if(sr->hdr.husk)
return;
207 if(!spillcutdef.first(sr))
continue;
208 for(
auto& spillweidef: spillcutdef.second){
209 const double wei = spillweidef.first(sr);
210 if(wei == 0)
continue;
211 for(
auto spillvardef: spillweidef.second){
212 if(spillvardef.first.IsMulti()){
213 for(
double val: spillvardef.first.GetMultiVar()(sr)){
214 for(
Spectrum*
s: spillvardef.second.spects) s->
Fill(val, wei);
218 const double val = spillvardef.first.GetVar()(sr);
219 for(
Spectrum*
s: spillvardef.second.spects) s->
Fill(val, wei);
227 const SpillCut& spillcut = spillcutdef.first;
229 const bool spillpass = spillcut(sr);
231 if(!spillpass)
continue;
242 for(
auto& shiftdef: spillcutdef.second){
249 caf::SRProxySystController::BeginTransaction();
251 bool shifted =
false;
253 double systWeight = 1;
256 shift.
Shift(&slc, systWeight);
259 shifted = caf::SRProxySystController::AnyShifted();
262 for(
auto& cutdef: shiftdef.second){
263 const Cut& cut = cutdef.first;
265 const bool pass = shifted ? cut(&slc) : nomCutCache.
Get(cut, &slc);
269 for(
auto& weidef: cutdef.second){
270 const Var& weivar = weidef.first;
272 double wei = shifted ? weivar(&slc) : nomWeiCache.
Get(weivar, &slc);
275 if(wei == 0)
continue;
277 for(
auto& vardef: weidef.second){
278 if(vardef.first.IsMulti()){
279 for(
double val: vardef.first.GetMultiVar()(&slc)){
286 const Var& var = vardef.first.GetVar();
288 const double val = shifted ? var(&slc) : nomVarCache.
Get(var, &slc);
290 if(std::isnan(val) || std::isinf(val)){
291 std::cerr <<
"Warning: Bad value: " << val
292 <<
" returned from a Var. The input variable(s) could "
293 <<
"be NaN in the CAF, or perhaps your "
294 <<
"Var code computed 0/0?";
295 std::cout <<
" Not filling into this histogram for this slice." << std::endl;
304 if(std::isnan(yval) || std::isinf(yval)){
305 std::cerr <<
"Warning: Bad value: " << yval
306 <<
" for reweighting Var";
307 std::cout <<
". Not filling into histogram." << std::endl;
311 rw->
fHist->Fill(val, yval, wei);
319 caf::SRProxySystController::Rollback();
336 for(
auto& spillcutdef: shiftdef.second){
337 for(
auto& cutdef: spillcutdef.second){
338 for(
auto& weidef: cutdef.second){
339 for(
auto& vardef: weidef.second){
356 for(
auto& spillweidef: spillcutdef.second){
357 for(
auto spillvardef: spillweidef.second){
358 for(
Spectrum*
s: spillvardef.second.spects){
const Var & ReweightVar() const
The variable that will be used to fill the y-axis.
virtual void StoreExposures()
Save accumulated exposures into the individual spectra.
virtual ~SpectrumLoader()
int max_entries
All unique cuts contained in fHistDefs.
BEGIN_PROLOG could also be cerr
bool fGone
Has Go() been called? Can't add more histograms after that.
Simple record of shifts applied to systematic parameters.
Spectrum with the value of a second variable, allowing for reweighting
SpectrumLoader(const std::string &wildcard, DataSource src=kBeam, int max=0)
void Fill(double x, double w=1)
process_name opflashCryoW ana
caf::Proxy< caf::SRSlice > SRSliceProxy
Representation of a spectrum in any variable, with associated POT.
void Shift(caf::SRSliceProxy *slc, double &weight) const
double fPOTFromHist
Accumulated by calls to GetNextFile.
IDMap< SpillCut, IDMap< SpillVar, IDMap< SpillVarOrMultiVar, SpectList > > > fSpillHistDefs
[spillcut][spillwei][spillvar]
IDMap< SpillCut, IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > > fHistDefs
All the spectra that need to be filled.
DataSource
Is this data-file representing beam spills or cosmic spills?
caf::Proxy< caf::StandardRecord > SRSpillProxy
bool operator()(const Cut &a, const Cut &b) const
virtual void HandleRecord(caf::SRSpillProxy *sr)
int ID() const
Cuts with the same definition will have the same ID.
virtual void Go() override
Load all the registered spectra.
static SpectrumLoader FromSAMProject(const std::string &proj, DataSource src=kBeam, int fileLimit=-1)
Named constructor for SAM projects.
T Get(const U &var, const V *sr)
Base class for the various types of spectrum loader.
std::unique_ptr< IFileSource > fFileSource
void SetProgress(double frac)
Update the progress fraction between zero and one.
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
then echo File list $list not found else cat $list while read file do echo $file sed s
A simple ascii-art progress bar.
Fetch files from a pre-existing SAM project.
virtual void HandleFile(TFile *f, Progress *prog=0)
int NFiles() const
Forwards to fFileSource.
std::vector< bool > fValsSet
void Done()
Call this when action is completed.
BEGIN_PROLOG could also be cout