Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ana::DecompWeightFunc Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-25/3FlavorAna/Vars/DecompWeights.h"

Public Member Functions

 DecompWeightFunc (const std::string &fname, const std::string &shortname, const Var &decompVar)
 
 ~DecompWeightFunc ()
 
double operator() (const caf::SRProxy *sr)
 

Protected Types

enum  {
  kNue, kAntiNue, kNumu, kAntiNumu,
  kNC, kNumComponents
}
 
enum  { kBeam, kAppearance, kIsOscillated }
 

Protected Member Functions

void InitializeHistograms () const
 
double GetWeight (const caf::SRProxy *sr) const
 

Protected Attributes

std::string fHistoFname
 
std::string fShortName
 
const Var fDecompVar
 
TH1D * fHistos [kNumComponents][kIsOscillated]
 

Detailed Description

Definition at line 12 of file DecompWeights.h.

Member Enumeration Documentation

anonymous enum
protected
anonymous enum
protected

Constructor & Destructor Documentation

ana::DecompWeightFunc::DecompWeightFunc ( const std::string fname,
const std::string shortname,
const Var decompVar 
)

Definition at line 17 of file DecompWeights.cxx.

20  : fHistoFname(fname), fShortName(shortname), fDecompVar(decompVar), fHistos()
21  {
22  }
TH1D * fHistos[kNumComponents][kIsOscillated]
Definition: DecompWeights.h:34
std::string fHistoFname
Definition: DecompWeights.h:30
std::string fShortName
Definition: DecompWeights.h:31
ana::DecompWeightFunc::~DecompWeightFunc ( )

Definition at line 25 of file DecompWeights.cxx.

References fHistos, kIsOscillated, kNumComponents, and submit_hadd::l.

26  {
27  for(int l = 0; l < kNumComponents; ++l){
28  for(int k = 0; k < kIsOscillated; ++k){
29  delete fHistos[l][k];
30  fHistos[l][k] = 0;
31  }
32  }
33  }
TH1D * fHistos[kNumComponents][kIsOscillated]
Definition: DecompWeights.h:34

Member Function Documentation

double ana::DecompWeightFunc::GetWeight ( const caf::SRProxy sr) const
protected

Definition at line 98 of file DecompWeights.cxx.

References om::cerr, allTimeWatchdog::endl, fDecompVar, fHistos, fShortName, make_syst_table_plots::h, InitializeHistograms(), kAntiNue, kAntiNumu, kAppearance, kBeam, kNC, kNue, kNumu, caf::Proxy< caf::StandardRecord >::mc, caf::Proxy< caf::SRTruthBranch >::nnu, and caf::Proxy< caf::SRTruthBranch >::nu.

Referenced by operator()().

99  {
101 
102  // Leave weight unaltered
103  if(sr->mc.nnu == 0) return 1;
104 
105  //Set the different weights for p/m sigma and neutrino flavor/energy
106 
107  double decompbin = fDecompVar(sr); // True neutrino energy
108 
109  //Find the component
110  int flav = 0;
111  switch(sr->mc.nu[0].pdg){
112  case 14: flav = kNumu; break;
113  case 12: flav = kNue; break;
114  case -14: flav = kAntiNumu; break;
115  case -12: flav = kAntiNue; break;
116  default: std::cerr << "Wrong nu flavor; ignore" << std::endl; return 1;
117  }
118  if(!sr->mc.nu[0].iscc)
119  flav = kNC;
120 
121  int osc = 0;
122  if(sr->mc.nu[0].pdgorig != sr->mc.nu[0].pdg)
123  osc = kAppearance;
124  else
125  osc = kBeam;
126 
127  //Find the right histogram
128  TH1D* h = fHistos[flav][osc];
129  if (h == 0){
130  std::cerr << fShortName+": Can't find desired histogram; ignore"<< std:: endl;
131  return 1;
132  }
133  //Only use weights if the energy is in the range of the histogram
134  if (decompbin >= h->GetXaxis()->GetXmin() &&
135  decompbin < h->GetXaxis()->GetXmax() ){
136  return h->GetBinContent(h->FindBin(decompbin));
137  }
138 
139  return 1;
140  }
TH1D * fHistos[kNumComponents][kIsOscillated]
Definition: DecompWeights.h:34
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:617
OStream cerr
Definition: OStream.cxx:7
caf::Proxy< short int > nnu
Definition: SRProxy.h:616
Oscillation probability calculators.
Definition: Calcs.h:5
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2137
std::string fShortName
Definition: DecompWeights.h:31
void InitializeHistograms() const
void ana::DecompWeightFunc::InitializeHistograms ( ) const
protected

Definition at line 36 of file DecompWeights.cxx.

References om::cerr, allTimeWatchdog::endl, fHistoFname, fHistos, fin, fShortName, compareCafs::histName, kAntiNue, kAntiNumu, kAppearance, kBeam, kNC, kNue, and kNumu.

Referenced by GetWeight().

37  {
38  // Already been called
39  if(fHistos[0][0]) return;
40 
41  //open file
42  TFile fin (fHistoFname.c_str(),"read");
43  if(fin.IsZombie()){
44  std::cerr << "Warning: couldn't open " << fHistoFname << std::endl;
45  return;
46  }
47 
48  //Check that desired systematic is in file
49  // Loop through the detector folder, over all histograms
50 
51  TIter iterHist(gDirectory->GetListOfKeys());
52  TKey* keyHist;
53  int foundHisto=0;
54  bool isSeparatedByFlavor = false;
55 
56  while((keyHist = (TKey*)iterHist())) {
57  TString histName = keyHist->GetName(); // Get a histogram name
58  if(histName.Contains(fShortName)){ //is it the desired syst
59  foundHisto++;
60 
61  int flav = 0;
62  if(histName.Contains("numu")) flav = kNumu;
63  if(histName.Contains("nue")) flav = kNue;
64  if(histName.Contains("antinumu")) flav = kAntiNumu;
65  if(histName.Contains("antinue")) flav = kAntiNue;
66  if(histName.Contains("nc")) flav = kNC;
67 
68  int osc = 0;
69  if(histName.Contains("beam")) osc = kBeam;
70  if(histName.Contains("app")) osc = kAppearance;
71 
72  //store relevant histograms
73  fHistos[flav][osc] = (TH1D*) fin.Get(histName)->Clone();
74  // disassociate it from the file it came from
75  fHistos[flav][osc]->SetDirectory(0);
76  }
77  if(histName.Contains("numu")){
78  isSeparatedByFlavor=true;
79  }
80  }
81 
82  if (foundHisto==0) {
83  std::cerr << "Decomp Ratios for "<< fShortName
84  << " not in this file; aborting" << std::endl;
85  abort();
86  }
87 
88  if (!isSeparatedByFlavor) {
89  std::cerr << "Decomp Ratios for "<< fShortName
90  << " doesn't have required flavor information; aborting"
91  << std::endl;
92  abort();
93  }
94  fin.Close();
95  }
TString fin
Definition: Style.C:24
TH1D * fHistos[kNumComponents][kIsOscillated]
Definition: DecompWeights.h:34
std::string fHistoFname
Definition: DecompWeights.h:30
OStream cerr
Definition: OStream.cxx:7
Oscillation probability calculators.
Definition: Calcs.h:5
std::string fShortName
Definition: DecompWeights.h:31
double ana::DecompWeightFunc::operator() ( const caf::SRProxy sr)
inline

Definition at line 21 of file DecompWeights.h.

References GetWeight().

21 { return GetWeight(sr); };
double GetWeight(const caf::SRProxy *sr) const

Member Data Documentation

const Var ana::DecompWeightFunc::fDecompVar
protected

Definition at line 32 of file DecompWeights.h.

Referenced by GetWeight().

std::string ana::DecompWeightFunc::fHistoFname
protected

Definition at line 30 of file DecompWeights.h.

Referenced by InitializeHistograms().

TH1D* ana::DecompWeightFunc::fHistos[kNumComponents][kIsOscillated]
mutableprotected

Definition at line 34 of file DecompWeights.h.

Referenced by GetWeight(), InitializeHistograms(), and ~DecompWeightFunc().

std::string ana::DecompWeightFunc::fShortName
protected

Definition at line 31 of file DecompWeights.h.

Referenced by GetWeight(), and InitializeHistograms().


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