FCCollection.cxx
Go to the documentation of this file.
2 
3 #include "CAFAna/Core/Progress.h"
5 
6 #include "TFile.h"
7 #include "TTree.h"
8 
9 #include <cassert>
10 #include <iostream>
11 
12 namespace ana
13 {
14  //----------------------------------------------------------------------
16  {
17  }
18 
19  //----------------------------------------------------------------------
21  {
22  const std::vector<std::string> fnames = Wildcard(wildcard);
23  if(fnames.empty()){
24  std::cout << "No files matching " << wildcard << std::endl;
25  abort();
26  }
27 
28  Progress prog(TString::Format("Loading FCCollection from %lu files matching '%s'", fnames.size(), wildcard.c_str()).Data());
29 
30  for(const std::string& fname: fnames){
31  const double fileFrac = double(&fname - &fnames.front())/fnames.size();
32 
33  TFile* fin = TFile::Open(pnfs2xrootd(fname).c_str());
34  assert(!fin->IsZombie());
35  TTree* tr = (TTree*)fin->Get("fc");
36  assert(tr);
37 
39  const unsigned int N = tr->GetEntries();
40 
41  fPts.reserve(fPts.size()+N);
42  for(unsigned int n = 0; n < N; ++n){
43  fPts.push_back(FCPoint::FromTree(tr, n));
44 
45  if(n % 1000 == 0)
46  prog.SetProgress(fileFrac + double(n)/(N*fnames.size()));
47  }
48 
49  delete fin;
50  } // end for fname
51 
52  prog.Done();
53  std::cout << "Loaded " << fPts.size() << " experiments." << std::endl;
54  }
55 
56  //----------------------------------------------------------------------
58  {
59  TFile fout(fname.c_str(), "RECREATE");
60  TTree tr("fc", "fc");
62  for(const FCPoint& pt : fPts) pt.ToTree(&tr);
63  tr.Write();
64  }
65 
66  //----------------------------------------------------------------------
67  std::unique_ptr<FCCollection> FCCollection::LoadFromFile(const std::string& wildcard)
68  {
69  std::unique_ptr<FCCollection> ret(new FCCollection);
70  ret->AddFiles(wildcard);
71  return ret;
72  }
73 }
TString fin
Definition: Style.C:24
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::vector< FCPoint > fPts
Definition: FCCollection.h:29
std::string pnfs2xrootd(std::string loc, bool unauth)
Definition: UtilsExt.cxx:237
Represents the results of a single Feldman-Cousins pseudo-experiment.
Definition: FCPoint.h:8
std::vector< std::string > Wildcard(const std::string &wildcardString)
Find files matching a UNIX glob, plus expand environment variables.
Definition: UtilsExt.cxx:268
static void InitToTree(TTree *tr)
Definition: FCPoint.cxx:20
void AddFiles(const std::string &wildcard)
std::vector< std::string > wildcard(const std::string &wildcardString)
Definition: convert.C:9
OStream cout
Definition: OStream.cxx:6
static void InitFromTree(TTree *tr)
Definition: FCPoint.cxx:75
assert(nhit_max >=nhit_nbins)
A simple ascii-art progress bar.
Definition: Progress.h:9
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
static FCPoint FromTree(TTree *tr, int idx)
Definition: FCPoint.cxx:101
void SaveToFile(const std::string &fname) const
static std::unique_ptr< FCCollection > LoadFromFile(const std::string &wildcard)
Collection of FCPoint. Serializable to/from a file.
Definition: FCCollection.h:12
enum BeamMode string