VarVals.cxx
Go to the documentation of this file.
1 /*
2  * VarVals.cxx
3  *
4  * Created on: June 13, 2016
5  * Author: J. Wolcott <jwolcott@fnal.gov>
6  */
7 
8 #include "cetlib_except/exception.h"
9 
11 
12 namespace cmf
13 {
14 
15  //----------------------------------------------------------------------------
16  // this is a bit clunky, but it allows us to avoid making objects just to store
17  // values the different variables.
18  float MCVarVals::val_at (uint8_t const& varkey) const
19  {
20  if (varkey == kTrueE ) return fTruthVars.fTrueE;
21  else if(varkey == kTruePDG ) return fTruthVars.fTruePDG;
22  else if(varkey == kTrueCCNC ) return fTruthVars.fTrueCCNC;
23  else if(varkey == kTrueIntType ) return fTruthVars.fTrueIntType;
24  else if(varkey == kTruePDGOrig ) return fTruthVars.fTruePDGOrig;
25  else if(varkey == kTrueParentPDG ) return fTruthVars.fTrueParentPDG;
26  else if(varkey == kTrueParentPT ) return fTruthVars.fTrueParentPT;
27  else if(varkey == kTrueParentPZ ) return fTruthVars.fTrueParentPZ;
28  else if(varkey == kTrueParentDecay ) return fTruthVars.fTrueParentDecay;
29  else if(varkey == kTrueParentTargetPDG) return fTruthVars.fTrueParentTargetPDG;
30  else if(varkey == kTrueHitNuc ) return fTruthVars.fTrueHitNuc;
31  else if(varkey == kTrueIntMode ) return fTruthVars.fTrueIntMode;
32 
33  else if(varkey == kXSecCVPPFX_Weight ) return fWeightVars.fXSecCVPPFX_Weight;
34  else if(varkey == kRPARES_Weight ) return fWeightVars.fRPARES_Weight;
35  else if(varkey == kXSecCV2020Wgt ) return fWeightVars.fXSecCV2020_Weight;
36  else if(varkey == kPPFXFluxCVWgt ) return fWeightVars.fPPFXFluxCV_Weight;
37 
38  throw cet::exception("VarVals")
39  << "Key: "
40  << varkey
41  << " does not correspond to any variable";
42 
43  return std::numeric_limits<float>::lowest();
44  }
45 
46  //----------------------------------------------------------------------------
47  std::map<float, float> MCVarVals::SystVarWgts(uint8_t const& varKey) const
48  {
49  // get the values for this genie systematic
50  auto itr = std::find(fSystematicShifts.begin(), fSystematicShifts.end(), varKey);
51  std::vector<float> vals = (itr != fSystematicShifts.end()) ? itr->SigmasAsVec() : std::vector<float>({1, 1, 1, 1});
52  // for(auto const& itr : fSystematicShifts){
53  // if(itr.Type() == varKey) vals = itr.SigmasAsVec();
54  // }
55 
56  // if the -2 and +2 sigma values are the same, then they aren't meaningful so don't
57  // add them to the map and only return the -1, 0 and +1 sigma values
58  if(vals[0] == vals[3])
59  return std::move(std::map<float, float>({ {-1., vals[1]},
60  { 0., 1.},
61  { 1., vals[2]} }));
62 
63  return std::move(std::map<float, float>({ {-2., vals[0]},
64  {-1., vals[1]},
65  { 0., 1.},
66  { 1., vals[2]},
67  { 2., vals[3]} }));
68  }
69 
70  //------------------------------------------------------------
71  std::ostream& operator<< (std::ostream& o, cmf::MCVarVals const& mcvv)
72  {
73  o << "Event MC related variables are: "
74  << "\n\t" << cmf::KeyToVarName(cmf::kTrueE) << " " << mcvv.val_at(cmf::kTrueE )
75  << "\n\t" << cmf::KeyToVarName(cmf::kTruePDG) << " " << mcvv.val_at(cmf::kTruePDG )
76  << "\n\t" << cmf::KeyToVarName(cmf::kTrueCCNC) << " " << mcvv.val_at(cmf::kTrueCCNC )
77  << "\n\t" << cmf::KeyToVarName(cmf::kTrueIntType) << " " << mcvv.val_at(cmf::kTrueIntType )
78  << "\n\t" << cmf::KeyToVarName(cmf::kTruePDGOrig) << " " << mcvv.val_at(cmf::kTruePDGOrig )
80  << "\n\t" << cmf::KeyToVarName(cmf::kTrueParentPT) << " " << mcvv.val_at(cmf::kTrueParentPT )
81  << "\n\t" << cmf::KeyToVarName(cmf::kTrueParentPZ) << " " << mcvv.val_at(cmf::kTrueParentPZ )
84  << "\n\t" << cmf::KeyToVarName(cmf::kTrueHitNuc) << " " << mcvv.val_at(cmf::kTrueHitNuc )
85  << "\n\t" << cmf::KeyToVarName(cmf::kTrueIntMode) << " " << mcvv.val_at(cmf::kTrueIntMode )
88  << "\n\t and too many GENIE knobs to list"
89  << std::endl;
90 
91  return o;
92  }
93 
94  //------------------------------------------------------------
95  std::ostream& operator<< (std::ostream& o, cmf::SystVar const& sv)
96  {
97  o << cmf::KeyToVarName(sv.fType)
98  << " | -2 sigma wgt: "
99  << sv.fMinus2Sigma
100  << " | -1 sigma wgt: "
101  << sv.fMinus1Sigma
102  << " | 1 sigma wgt: "
103  << sv.fPlus1Sigma
104  << " | 2 sigma wgt: "
105  << sv.fPlus2Sigma
106  << " | ";
107 
108  return o;
109  }
110 
111  //------------------------------------------------------------
112  bool EventId::operator==(EventId const& other) const
113  {
114  return (this->run == other.run &&
115  this->subrun == other.subrun &&
116  this->cycle == other.cycle &&
117  this->event == other.event &&
118  this->slice == other.slice);
119  }
120 
121  //------------------------------------------------------------
122  bool EventId::operator<(EventId const& other) const
123  {
124  if(this->run < other.run) return true;
125  else if(this->run == other.run){
126  if(this->subrun < other.subrun) return true;
127  else if(this->subrun == other.subrun){
128  if(this->cycle < other.cycle) return true;
129  else if(this->cycle == other.cycle){
130  if(this->event < other.event) return true;
131  else if(this->event == other.event){
132  if(this->slice < other.slice) return true;
133  }
134  }
135  }
136  }
137 
138  return false;
139  }
140 
141  //------------------------------------------------------------
142  std::ostream& operator<< (std::ostream& o, cmf::EventId const& evid)
143  {
144  o << "run "
145  << evid.run
146  << "\tsubrun "
147  << evid.subrun
148  << "\tevent "
149  << evid.event
150  << "\tcycle "
151  << evid.cycle
152  << "\tslice "
153  << evid.slice;
154 
155  return o;
156  }
157 
158  //----------------------------------------------------------------------------
159  // this is a bit clunky, but it allows us to avoid making objects just to store
160  // values the different variables.
161  float DataVarVals::val_at(uint8_t const& varkey,
162  cmf::MetaData const& md) const
163  {
164  if (varkey == kNuE_CVN ) return fDataVars.fNuE_CVN;
165  else if(varkey == kNuE_NumMichel ) return fDataVars.fNuE_NumMichel;
166  else if(varkey == kNu_RecoE ) return fDataVars.fNu_RecoE;
167  else if(varkey == kHad_RecoE ) return fDataVars.fHad_RecoE;
168  else if(varkey == kLep_RecoE ) return fDataVars.fLep_RecoE;
169  else if(varkey == kLep_RecoE_MCFrac) return fDataVars.fLep_RecoE_MCFrac;
170  else if(varkey == kRecoQ2 ) return fDataVars.fRecoQ2;
171  else if(varkey == kFake_Weight ) return fDataVars.fFake_Weight;
172  else if(varkey == kCMF_RecoE ) return this->NuRecoEVal(md);
173 
174  return std::numeric_limits<float>::lowest();
175  }
176 
177  //----------------------------------------------------------------------------
178  void DataVarVals::set_val_at (uint8_t const& varkey,
179  float const& val)
180  {
181  if (varkey == kNuE_CVN ) fDataVars.fNuE_CVN = val;
182  else if(varkey == kNuE_NumMichel ) fDataVars.fNuE_NumMichel = val;
183  else if(varkey == kNu_RecoE ) fDataVars.fNu_RecoE = val;
184  else if(varkey == kHad_RecoE ) fDataVars.fHad_RecoE = val;
185  else if(varkey == kLep_RecoE ) fDataVars.fLep_RecoE = val;
186  else if(varkey == kLep_RecoE_MCFrac) fDataVars.fLep_RecoE_MCFrac = val;
187  else if(varkey == kRecoQ2 ) fDataVars.fRecoQ2 = val;
188  else if(varkey == kFake_Weight ) fDataVars.fFake_Weight = val;
189  else
190  LOG_DEBUG("DataVarVals")
191  << "unable to set Data var "
192  << cmf::KeyToVarName(varkey)
193  << " because the key is unknown";
194  }
195 
196  //----------------------------------------------------------------------------
197  inline float cmf::DataVarVals::NuRecoEVal(cmf::MetaData const& md) const
198  {
199  return cmf::RecoEnergy(fDataVars.fLep_RecoE,
200  fDataVars.fHad_RecoE,
201  md);
202  }
203 
204  //------------------------------------------------------------
205  std::ostream& operator<< (std::ostream& o, cmf::DataVarVals const& dvv)
206  {
207  cmf::MetaData numumd;
208  cmf::MetaData nuemd;
209 
210  numumd.isMC = false;
211  nuemd .isMC = false;
214 
215  o << "Event Data related variables are: "
216  << "\n\t" << cmf::KeyToVarName(cmf::kNuE_CVN) << " " << dvv.val_at(cmf::kNuE_CVN, nuemd )
217  << "\n\t" << cmf::KeyToVarName(cmf::kNuE_NumMichel) << " " << dvv.val_at(cmf::kNuE_NumMichel, nuemd )
218  << "\n\t" << cmf::KeyToVarName(cmf::kHad_RecoE) << " " << dvv.val_at(cmf::kHad_RecoE, nuemd )
219  << "\n\t" << cmf::KeyToVarName(cmf::kLep_RecoE) << " " << dvv.val_at(cmf::kLep_RecoE, nuemd )
220  << "\n\t" << cmf::KeyToVarName(cmf::kLep_RecoE_MCFrac) << " " << dvv.val_at(cmf::kLep_RecoE_MCFrac, numumd)
221  << "\n\t" << cmf::KeyToVarName(cmf::kNu_RecoE ) << " nue " << dvv.val_at(cmf::kNu_RecoE, nuemd )
222  << "\n\t" << cmf::KeyToVarName(cmf::kNu_RecoE ) << " numu " << dvv.val_at(cmf::kNu_RecoE, numumd)
223  << "\n\t" << cmf::KeyToVarName(cmf::kFake_Weight) << " " << dvv.val_at(cmf::kFake_Weight, nuemd )
224  << std::endl;
225 
226  return o;
227  }
228 
229 } /* namespace cmf */
float fMinus2Sigma
weight associated with this change in the underlying parameter
Definition: VarVals.h:196
float fTruePDGOrig
true PDG of original neutrino
Definition: VarVals.h:46
bool operator==(EventId const &evid) const
Definition: VarVals.cxx:112
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
cmf::WeightVars fWeightVars
Definition: VarVals.h:231
friend std::ostream & operator<<(std::ostream &o, cmf::MCVarVals const &mcvv)
Definition: VarVals.cxx:71
float fPPFXFluxCV_Weight
For 2020 Ana, store weights seperately.
Definition: VarVals.h:159
float fTrueHitNuc
true hit nucleus
Definition: VarVals.h:52
float fTrueCCNC
true cc vs nc
Definition: VarVals.h:44
float fTrueParentDecay
true parent decay mode
Definition: VarVals.h:50
float fTruePDG
true PDG
Definition: VarVals.h:43
std::map< float, float > SystVarWgts(uint8_t const &varkey) const
Definition: VarVals.cxx:47
float fPlus2Sigma
weight associated with this change in the underlying parameter
Definition: VarVals.h:199
float fTrueParentPT
true p_T of neutrino parent
Definition: VarVals.h:48
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
uint8_t fType
key for this parameter
Definition: VarVals.h:195
float fRPARES_Weight
To be used for systematic evaluation ONLY.
Definition: VarVals.h:152
cmf::SystVarColl fSystematicShifts
Definition: VarVals.h:232
float fTrueE
True nu energy.
Definition: VarVals.h:42
Base container for the MC related Vars that constitute an event.
Definition: VarVals.h:227
int subrun
Definition: VarVals.h:80
float fTrueParentPDG
true PDG of neutrino parent
Definition: VarVals.h:47
cmf::TruthVars fTruthVars
Definition: VarVals.h:230
cmf::SelectionType_t selectionType
Definition: Structs.h:116
float fMinus1Sigma
weight associated with this change in the underlying parameter
Definition: VarVals.h:197
int cycle
Definition: VarVals.h:82
void set_val_at(uint8_t const &varkey, float const &val)
Definition: VarVals.cxx:178
float fXSecCV2020_Weight
For 2020 Ana, store weights seperately.
Definition: VarVals.h:158
float val_at(uint8_t const &varkey, cmf::MetaData const &md) const
Definition: VarVals.cxx:161
int slice
Definition: VarVals.h:83
Base container for the MC related Vars that constitute an event.
Definition: VarVals.h:268
float fXSecCVPPFX_Weight
Deprecated, Was Tufts weight for SA.
Definition: VarVals.h:150
float fTrueParentPZ
true p_Z of neutrino parent
Definition: VarVals.h:49
Definition: run.py:1
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
static float RecoEnergy(float leptonicEnergy, float hadronicEnergy, cmf::MetaData const &md)
Definition: VarVals.h:317
float val_at(uint8_t const &varkey) const
Access a Var by name.
Definition: VarVals.cxx:18
bool operator<(EventId const &evid) const
Definition: VarVals.cxx:122
float NuRecoEVal(cmf::MetaData const &md) const
Definition: VarVals.cxx:197
float fTrueIntType
true interaction type
Definition: VarVals.h:45
float fTrueIntMode
true interaction mode
Definition: VarVals.h:53
int event
Definition: VarVals.h:81
static std::string KeyToVarName(uint8_t const &key)
Definition: StaticFuncs.h:410
float fTrueParentTargetPDG
true parent pdg code off the target
Definition: VarVals.h:51
float fPlus1Sigma
weight associated with this change in the underlying parameter
Definition: VarVals.h:198