Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
lem::Library Class Reference

Collection of events for matching. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-05-06/LEM/func/Library.h"

Public Member Functions

 ~Library ()
 
const LibrarySummarySummary () const
 
unsigned int NEvents () const
 
const MatchableEventEvent (int i) const
 
const MatchableEventDownsampledEvent (int i) const
 
const MatchableEventEvents () const
 
const MatchableEventDownsampledEvents () const
 

Static Public Member Functions

static LibraryFromMMap (const std::string &libPath, bool touchAll)
 
static LibraryFromMMapOnDemand (const std::string &libPath)
 
static LibraryFromTrees (const std::string &libPath, int splitLibFactor, int splitLibIndex, int downsampleFactor)
 

Protected Member Functions

 Library ()
 
 Library (const Library &)
 
Libraryoperator= (const Library &)
 

Static Protected Member Functions

static double SimpleSurvivalProb (const EventSummary &evt)
 

Protected Attributes

LibrarySummary fSummary
 
unsigned int fLibSize
 
MatchableEventfLib
 
MatchableEventfLibDownsample
 
long fMappingSize
 

Detailed Description

Collection of events for matching.

Definition at line 18 of file Library.h.

Constructor & Destructor Documentation

lem::Library::~Library ( )

Definition at line 187 of file Library.cxx.

References fLib, fLibDownsample, and fMappingSize.

188  {
189  if(fMappingSize != 0){
190  // munmap(kLibAddr, fMappingSize);
191  }
192  else{
193  // Was loaded from trees
194  delete[] fLib;
195  delete[] fLibDownsample;
196  }
197  }
long fMappingSize
Definition: Library.h:49
MatchableEvent * fLib
Definition: Library.h:46
MatchableEvent * fLibDownsample
Definition: Library.h:47
lem::Library::Library ( )
inlineprotected

Definition at line 38 of file Library.h.

References evt, operator=(), and SimpleSurvivalProb().

Referenced by FromMMap(), FromMMapOnDemand(), and FromTrees().

38 {}
lem::Library::Library ( const Library )
protected

Member Function Documentation

const MatchableEvent& lem::Library::DownsampledEvent ( int  i) const
inline

Definition at line 33 of file Library.h.

References fLibDownsample, and MECModelEnuComparisons::i.

Referenced by lem::FindMatchesTranspose::endRun().

33 {return fLibDownsample[i];}
MatchableEvent * fLibDownsample
Definition: Library.h:47
const MatchableEvent* lem::Library::DownsampledEvents ( ) const
inline

Definition at line 35 of file Library.h.

References fLibDownsample.

Referenced by lem::LEM::produce().

35 {return fLibDownsample;}
MatchableEvent * fLibDownsample
Definition: Library.h:47
const MatchableEvent& lem::Library::Event ( int  i) const
inline
const MatchableEvent* lem::Library::Events ( ) const
inline

Definition at line 34 of file Library.h.

References fLib.

Referenced by lem::LEM::produce().

34 {return fLib;}
MatchableEvent * fLib
Definition: Library.h:46
Library * lem::Library::FromMMap ( const std::string libPath,
bool  touchAll 
)
static

Definition at line 62 of file Library.cxx.

References fLib, fLibDownsample, fLibSize, fMappingSize, fSummary, cvnie::lib, Library(), lem::MMapFileAtAddress(), and lem::LibrarySummary::N.

Referenced by lem::LEM::beginJob(), dump_event(), lem::FindMatchesTranspose::endRun(), lem::FindMatchesAlg::FindMatchesAlg(), lem::LEMLibrary::LEMLibrary(), preload_lib(), show_event(), and show_potential().

64  {
65  Library* lib = new Library;
66 
67  lib->fMappingSize = MMapFileAtAddress(libPath+"/map.bin", kLibAddr,
68  touchAll, "/tmp/lem_preload_lib.lock");
69 
70  lib->fSummary = *((LibrarySummary*)kLibAddr);
71 
72  lib->fLibSize = lib->fSummary.N;
73 
74  lib->fLib = (MatchableEvent*)((char*)kLibAddr+sizeof(LibrarySummary));
75 
76  lib->fLibDownsample = (MatchableEvent*)((char*)lib->fLib+lib->fLibSize*sizeof(MatchableEvent));
77 
78  return lib;
79  }
Definition: __init__.py:1
long MMapFileAtAddress(const std::string &fname, void *addr, bool touchAll, const std::string &lockName)
Definition: Util.cxx:18
string lib
Definition: cvnie.py:9
Library * lem::Library::FromMMapOnDemand ( const std::string libPath)
static

Definition at line 82 of file Library.cxx.

References lem::CreateOnDemandMapping(), fLib, fLibDownsample, fLibSize, fSummary, cvnie::lib, Library(), and lem::LibrarySummary::N.

Referenced by lem::LEM::beginJob(), lem::FindMatchesTranspose::endRun(), and lem::LEMLibrary::LEMLibrary().

83  {
84  CreateOnDemandMapping((libPath+"/map.bin").c_str(), kLibAddr);
85 
86  Library* lib = new Library;
87 
88  lib->fSummary = *((LibrarySummary*)kLibAddr);
89 
90  lib->fLibSize = lib->fSummary.N;
91 
92  lib->fLib = (MatchableEvent*)((char*)kLibAddr+sizeof(LibrarySummary));
93 
94  lib->fLibDownsample = (MatchableEvent*)((char*)lib->fLib+lib->fLibSize*sizeof(MatchableEvent));
95 
96  return lib;
97  }
Definition: __init__.py:1
string lib
Definition: cvnie.py:9
void CreateOnDemandMapping(const std::string &fname, const char *base)
Definition: OnDemand.cxx:123
Library * lem::Library::FromTrees ( const std::string libPath,
int  splitLibFactor,
int  splitLibIndex,
int  downsampleFactor 
)
static

Definition at line 100 of file Library.cxx.

References ana::assert(), lem::EventSummary::ccnc, om::cout, lem::MatchableEvent::Downsampled(), allTimeWatchdog::endl, evt, fLib, fLibDownsample, fLibSize, fMappingSize, lem::EventSummary::FromTree(), fSummary, lem::EventSummary::id, lem::EventSummary::InitFromTree(), lem::EventSummary::IsSig(), cvnie::lib, Library(), lem::LibrarySummary::nSwapNC, lem::LibrarySummary::nTrueNC, lem::EventSummary::origPdg, P, lem::EventSummary::pdg, SimpleSurvivalProb(), sum, lem::LibrarySummary::totBkg, lem::LibrarySummary::totEnrich, lem::LibrarySummary::totSig, and lem::MatchableEvent::weight.

Referenced by lem::LEM::beginJob(), and lem::LEMLibrary::LEMLibrary().

104  {
105  // TODO: this order won't match what heads is expecting
106 
107  TChain ch("makelib/tree");
108  ch.Add((libPath+"/lem_hist_sig.root").c_str());
109  ch.Add((libPath+"/lem_hist_bkg.root").c_str());
110  const int Nunenrich = ch.GetEntries();
111  ch.Add((libPath+"/lem_hist_enrich.root").c_str());
112 
114 
115  const int startIdx = (splitLibIndex*ch.GetEntries())/splitLibFactor;
116  const int endIdx = ((splitLibIndex+1)*ch.GetEntries())/splitLibFactor;
117 
118  const int N = endIdx-startIdx;
119 
120  assert(N > 0);
121 
122  std::cout << "Loading libraries..." << std::endl;
123  int nSig = 0, nBkg = 0;
124  double totSig = 0, totBkg = 0, totEnrich = 0;
125  int nTrueNC = 0, nSwapNC = 0;
126 
127  Library* lib = new Library;
128  lib->fMappingSize = 0;
129 
130  lib->fLibSize = N;
131  lib->fLib = new MatchableEvent[N];
132  lib->fLibDownsample = new MatchableEvent[N];
133 
134  for(int n = startIdx; n < endIdx; ++n){
135  if((n-startIdx)%10000 == 0)
136  std::cout << (n-startIdx)/10000 << "/" << N/10000 << std::endl;
137 
138  const bool isEnrich = n >= Nunenrich;
139  EventSummary sum = EventSummary::FromTree(&ch, n, isEnrich);
140  sum.id = n;
141 
142  // This has to happen here, and not in MakePID where the other
143  // reweighting happens, because it feeds into the totals for the
144  // different event classes that we write out.
145  const double P = isEnrich ? 1 : SimpleSurvivalProb(sum);
146  // Screws up indexing, don't do it. FindMatches can cope
147  // if(P == 0) continue; // beam nue
148 
150  evt.weight = P;
151 
152  if(!isEnrich && sum.ccnc == 1){
153  if(sum.pdg == sum.origPdg) ++nTrueNC; else ++nSwapNC;
154  }
155 
156  lib->fLib[n-startIdx] = evt;
157 
158  lib->fLibDownsample[n-startIdx] = evt.Downsampled(downsampleFactor);
159 
160  if(isEnrich){
161  ++totEnrich;
162  }
163  else{
164  if(evt.IsSig()){
165  ++nSig;
166  totSig += P;
167  }
168  else{
169  ++nBkg;
170  totBkg += P;
171  }
172  }
173  } // end for n
174 
175  lib->fSummary.nTrueNC = nTrueNC;
176  lib->fSummary.nSwapNC = nSwapNC;
177  lib->fSummary.totBkg = totBkg;
178  lib->fSummary.totSig = totSig;
179  lib->fSummary.totEnrich = totEnrich;
180 
181  std::cout << "Loaded " << lib->fSummary << std::endl;
182 
183  return lib;
184  }
Attach some information used in matching to an EventSummary.
static void InitFromTree(TTree *tr)
Definition: __init__.py:1
#define P(a, b, c, d, e, x)
string lib
Definition: cvnie.py:9
std::void_t< T > n
int evt
static EventSummary FromTree(TTree *tr, int evtIdx, bool enrich)
OStream cout
Definition: OStream.cxx:6
static double SimpleSurvivalProb(const EventSummary &evt)
Definition: Library.cxx:28
assert(nhit_max >=nhit_nbins)
Double_t sum
Definition: plot.C:31
unsigned int lem::Library::NEvents ( ) const
inline

Definition at line 31 of file Library.h.

References fLibSize.

Referenced by lem::FindMatchesTranspose::endRun(), and lem::LEM::produce().

31 {return fLibSize;}
unsigned int fLibSize
Definition: Library.h:45
Library& lem::Library::operator= ( const Library )
protected

Referenced by Library().

double lem::Library::SimpleSurvivalProb ( const EventSummary evt)
staticprotected

Definition at line 28 of file Library.cxx.

References abs(), lem::EventSummary::ccnc, e, lem::EventSummary::IsSig(), lem::EventSummary::origPdg, lem::EventSummary::pdg, std::sin(), util::sqr(), and lem::EventSummary::trueEVis.

Referenced by FromTrees(), and Library().

29  {
30  if(evt.IsSig()){
31  // Scale up to keep as much signal as possible in sample, weighted
32  // correctly internally. The missing prefactor is (ss2th13*ssth23)
33  return util::sqr(sin(1.267*2.35e-3*810/evt.trueEVis));
34  }
35  if(evt.ccnc == 0 && abs(evt.pdg) == 14 && abs(evt.origPdg) == 14){
36  // CC mu
37  return 1-util::sqr(sin(1.267*2.35e-3*810/evt.trueEVis));
38  }
39  if(evt.ccnc == 0 && abs(evt.pdg) == 12 && abs(evt.origPdg) == 12){
40  // Beam nue
41  // return 1-.1*util::sqr(sin(1.267*2.35e-3*810/evt.trueEVis));
42  // Want library matching to ignore nues
43  return 0;
44  }
45  if(evt.ccnc == 1 && evt.pdg == evt.origPdg){
46  // NC
47  return 1;
48  }
49  if(evt.ccnc == 1 && evt.pdg != evt.origPdg){
50  // Swapped NC. We play clever reweighting games so this is OK
51  return 1;
52  }
53  if(evt.ccnc == 0 && abs(evt.pdg) == 14 && abs(evt.origPdg) == 12){
54  // CC mu appearance, take ss2th13=0.1, maximal th23
55  return .1*.5*util::sqr(sin(1.267*2.35e-3*810/evt.trueEVis));
56  }
57  // Don't know what this is
58  return 0;
59  }
void abs(TH1 *hist)
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
int evt
T sin(T number)
Definition: d0nt_math.hpp:132
Float_t e
Definition: plot.C:35
const LibrarySummary& lem::Library::Summary ( ) const
inline

Definition at line 30 of file Library.h.

References fSummary.

Referenced by lem::FindLEMMatches::beginRun(), lem::LEM::beginRun(), and lem::FindMatchesTranspose::endRun().

30 {return fSummary;}
LibrarySummary fSummary
Definition: Library.h:44

Member Data Documentation

MatchableEvent* lem::Library::fLib
protected

Definition at line 46 of file Library.h.

Referenced by Event(), Events(), FromMMap(), FromMMapOnDemand(), FromTrees(), and ~Library().

MatchableEvent* lem::Library::fLibDownsample
protected
unsigned int lem::Library::fLibSize
protected

Definition at line 45 of file Library.h.

Referenced by FromMMap(), FromMMapOnDemand(), FromTrees(), and NEvents().

long lem::Library::fMappingSize
protected

Definition at line 49 of file Library.h.

Referenced by FromMMap(), FromTrees(), and ~Library().

LibrarySummary lem::Library::fSummary
protected

Definition at line 44 of file Library.h.

Referenced by FromMMap(), FromMMapOnDemand(), FromTrees(), and Summary().


The documentation for this class was generated from the following files: