Classes | Functions | Variables
KinematicsHistos.C File Reference
#include <algorithm>
#include <exception>
#include <iomanip>
#include <memory>
#include <unordered_map>
#include <set>
#include <string>
#include "TFile.h"
#include "TMath.h"
#include "TParameter.h"
#include "StandardRecord/Proxy/SRProxy.h"
#include "StandardRecord/SRNeutrino.h"
#include "CAFAna/Analysis/SALoaders.h"
#include "CAFAna/Analysis/Prod3Loaders.h"
#include "CAFAna/Cuts/Cuts.h"
#include "3FlavorAna/Cuts/NumuCuts2018.h"
#include "CAFAna/Cuts/SpillCuts.h"
#include "CAFAna/Cuts/TruthCuts.h"
#include "CAFAna/Core/Spectrum.h"
#include "CAFAna/Core/SpectrumLoader.h"
#include "CAFAna/Vars/Vars.h"
#include "3FlavorAna/Vars/NumuVars.h"
#include "CAFAna/Vars/GenieWeights.h"
#include "CAFAna/Vars/PPFXWeights.h"
#include "CAFAna/Vars/TruthVars.h"

Go to the source code of this file.

Classes

struct  IntConfig
 
class  IOManager
 

Functions

ana::Cut Q3CutFactory (float lb, float ub)
 
void MakeObservablesSpectra (const IOManager &mgr, std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &spectra)
 
void MakeTruthSpectra (const IOManager &mgr, std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &spectra)
 Plots of truth-only quantities (weights applied; true kinematics) More...
 
void SaveSpectra (std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &spectra, const IOManager &mgr)
 
void KinematicsHistos (std::string hornCurrent, std::string productionName, std::string dataMC="")
 

Variables

const std::set< std::stringKNOWN_DATASETS
 
const std::string BASE_DIR = "/nova/ana/users/jwolcott/2p2h_tuning/2018/hists"
 
const ana::Var kVisMuHadE ([](const caf::SRProxy *sr){return kMuE(sr)+ana::kNumuHadVisE(sr);})
 
const std::unordered_map< std::string, ana::HistAxisOBSERVABLE_HIST_AXES
 
const std::unordered_map< std::string, ana::HistAxisTRUTH_HIST_AXES
 
const std::unordered_map< caf::mode_type_, IntConfig, std::hash< int > > INT_CONFIG
 
const ana::Var kNonQEMECWgt
 
const std::unordered_map< std::string, ana::VarMECQE_WGTS
 
const std::unordered_map< std::string, std::unordered_map< std::string, ana::Cut > > SLICE_BREAKDOWNS
 

Function Documentation

void KinematicsHistos ( std::string  hornCurrent,
std::string  productionName,
std::string  dataMC = "" 
)

Definition at line 429 of file KinematicsHistos.C.

References IOManager::GetDataMC(), IOManager::GetLoader(), ana::SpectrumLoaderBase::Go(), ana::Loaders::kMC, MakeObservablesSpectra(), MakeTruthSpectra(), and SaveSpectra().

430 {
431  IOManager mgr(hornCurrent, productionName, dataMC);
432 
433  std::unordered_map<std::string, std::unique_ptr<ana::Spectrum>> allSpectra;
434  MakeObservablesSpectra(mgr, allSpectra);
435  if (mgr.GetDataMC() == ana::Loaders::kMC)
436  MakeTruthSpectra(mgr, allSpectra);
437 
438  // Do it!
439  mgr.GetLoader().Go();
440 
441  SaveSpectra(allSpectra, mgr);
442 
443 }
void SaveSpectra(std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &spectra, const IOManager &mgr)
void MakeObservablesSpectra(const IOManager &mgr, std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &spectra)
void MakeTruthSpectra(const IOManager &mgr, std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &spectra)
Plots of truth-only quantities (weights applied; true kinematics)
void MakeObservablesSpectra ( const IOManager mgr,
std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &  spectra 
)

Plots of 'observables' (or things near to it): Emu, Ehad, Enu If data, one Spectrum for each Var If MC, one Spectrum per Var per interaction class, split further by which weights were applied

Definition at line 332 of file KinematicsHistos.C.

References allInOneTrainingPlots::axis, update_sam_good_runs_metadata::cuts, IOManager::GetDataMC(), IOManager::GetLoader(), INT_CONFIG, ana::Loaders::kData, ana::kNoCut, kNonQEMECWgt, ana::kNoShift, ana::kNumuCutND2018, MECQE_WGTS, OBSERVABLE_HIST_AXES, IntConfig::selCut, SLICE_BREAKDOWNS, and string.

Referenced by KinematicsHistos().

333 {
334  ana::Cut selCut = ana::kNumuCutND2018;
335  decltype(SLICE_BREAKDOWNS)::mapped_type no_slice { {"", ana::kNoCut} };
336 
337  for (const auto & axisPair : OBSERVABLE_HIST_AXES)
338  {
339  const auto & slices = (SLICE_BREAKDOWNS.find(axisPair.first) == SLICE_BREAKDOWNS.end()) ? no_slice : SLICE_BREAKDOWNS.at(axisPair.first);
340  for (const auto slicePair : slices)
341  {
342  auto plotname = axisPair.first + slicePair.first;
343  auto & axis = axisPair.second;
344  if (mgr.GetDataMC() == ana::Loaders::kData)
345  {
346  spectra.emplace(plotname, // var name
347  std::make_unique<ana::Spectrum>(mgr.GetLoader(), axis, selCut && slicePair.second)
348  );
349  continue;
350  }
351 
352  // MC is more complicated... breakdowns by interaction type; versions for various weightings
353  for (const auto & mecWgtPair : MECQE_WGTS)
354  {
355  auto wgts = mecWgtPair.second * kNonQEMECWgt;
356  for (const auto & intPair : INT_CONFIG)
357  {
358  std::string name = Form("%s{group=mecWgt,cat=%s}{group=interaction,cat=%s}", plotname.c_str(), mecWgtPair.first.c_str(), intPair.second.name.c_str());
359  // std::cout << " preparing Spectrum " << std::quoted(name) << std::endl;
360  auto cuts = selCut && slicePair.second && intPair.second.selCut;
361  spectra.emplace(name,
362  std::make_unique<ana::Spectrum>(mgr.GetLoader(), axis, cuts, ana::kNoShift, wgts)
363  );
364  } // for (intPair)
365  } // for (mecWgtPair)
366  } //for (slice)
367  } // for (configPair)
368 } // MakeObservableSpectra()
const XML_Char * name
Definition: expat.h:151
const std::unordered_map< std::string, std::unordered_map< std::string, ana::Cut > > SLICE_BREAKDOWNS
const Cut kNumuCutND2018
Definition: NumuCuts2018.h:41
const std::unordered_map< caf::mode_type_, IntConfig, std::hash< int > > INT_CONFIG
const ana::Var kNonQEMECWgt
const std::unordered_map< std::string, ana::HistAxis > OBSERVABLE_HIST_AXES
const std::unordered_map< std::string, ana::Var > MECQE_WGTS
ana::Loaders::DataMC GetDataMC() const
ana::SpectrumLoaderBase & GetLoader() const
const SystShifts kNoShift
Definition: SystShifts.cxx:22
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
enum BeamMode string
void MakeTruthSpectra ( const IOManager mgr,
std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &  spectra 
)

Plots of truth-only quantities (weights applied; true kinematics)

Definition at line 373 of file KinematicsHistos.C.

References allInOneTrainingPlots::axis, update_sam_good_runs_metadata::cuts, IOManager::GetLoader(), INT_CONFIG, kNonQEMECWgt, ana::kNoShift, ana::kNumuND, MECQE_WGTS, allTimeWatchdog::plotName, ana::Binning::Simple(), string, and TRUTH_HIST_AXES.

Referenced by KinematicsHistos().

374 {
375  for (const auto & intPair : INT_CONFIG)
376  {
377 
378  // plot the weights themselves
379  for (const auto & wgtPair : MECQE_WGTS)
380  {
381  std::string name = Form("weight{group=mecWgt,cat=%s}{group=interaction,cat=%s}", wgtPair.first.c_str(), intPair.second.name.c_str());
382  auto cuts = ana::kNumuND && intPair.second.selCut;
383  spectra.emplace(name,
384  std::make_unique<ana::Spectrum>(name, ana::Binning::Simple(100, 0, 2), mgr.GetLoader(), wgtPair.second, cuts)
385  );
386  } // for (wgtPair)
387 
388  // and true event spectra. useful for debugging what happened
389  for (const auto & mecWgtPair : MECQE_WGTS)
390  {
391  auto wgts = mecWgtPair.second * kNonQEMECWgt;
392  for (const auto & configPair : TRUTH_HIST_AXES)
393  {
394  const auto & name = configPair.first;
395  const auto & axis = configPair.second;
396  std::string plotName = Form("%s{group=mecWgt,cat=%s}{group=interaction,cat=%s}", configPair.first.c_str(), mecWgtPair.first.c_str(), intPair.second.name.c_str());
397  spectra.emplace(plotName,
398  std::make_unique<ana::Spectrum>(
399  mgr.GetLoader(),
400  axis,
401  intPair.second.selCut,
403  wgts
404  )
405  );
406 
407  } // for (config)
408 
409  } // for (xsecWgts)
410  } // for (intPair)
411 } // MakeTruthSpectra()
const XML_Char * name
Definition: expat.h:151
const std::unordered_map< caf::mode_type_, IntConfig, std::hash< int > > INT_CONFIG
const ana::Var kNonQEMECWgt
const std::unordered_map< std::string, ana::Var > MECQE_WGTS
const std::unordered_map< std::string, ana::HistAxis > TRUTH_HIST_AXES
const Cut kNumuND
Definition: NumuCuts.h:55
ana::SpectrumLoaderBase & GetLoader() const
const SystShifts kNoShift
Definition: SystShifts.cxx:22
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
enum BeamMode string
ana::Cut Q3CutFactory ( float  lb,
float  ub 
)

Definition at line 90 of file KinematicsHistos.C.

References ana::kRecoQmag, and genie::units::ub.

91 {
92  return std::move(ana::Cut([lb, ub](const caf::SRProxy * sr)
93  {
94  double q3 = ana::kRecoQmag(sr);
95  return lb <= q3 && q3 <= ub;
96  }
97  ));
98 }
const Var kRecoQmag([](const caf::SRProxy *sr){return sqrt(kRecoQ2(sr)+util::sqr(kHadE(sr)));})
Reconstructed three-momentum transfer.
Definition: NumuVars.h:149
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
caf::StandardRecord * sr
static const double ub
Definition: Units.h:88
void SaveSpectra ( std::unordered_map< std::string, std::unique_ptr< ana::Spectrum >> &  spectra,
const IOManager mgr 
)

Definition at line 417 of file KinematicsHistos.C.

References om::cout, allTimeWatchdog::endl, outFile, and IOManager::TagNameBySample().

Referenced by KinematicsHistos().

418 {
419  TFile outFile(mgr.TagNameBySample("rwgt_spectra.root").c_str(), "recreate");
420  std::cout << "Saving spectra to TFile: " << std::quoted(outFile.GetName()) << std::endl;
421  for (const auto & specPair : spectra)
422  specPair.second->SaveTo(&outFile, specPair.first.c_str());
423 }
TFile * outFile
Definition: PlotXSec.C:135
OStream cout
Definition: OStream.cxx:6
std::string TagNameBySample(const std::string &name) const

Variable Documentation

const std::string BASE_DIR = "/nova/ana/users/jwolcott/2p2h_tuning/2018/hists"

Definition at line 62 of file KinematicsHistos.C.

Referenced by IOManager::TagNameBySample().

const std::unordered_map<caf::mode_type_, IntConfig, std::hash<int> > INT_CONFIG
Initial value:
{
{caf::kQE, IntConfig("QE", ana::kIsNumuCC && ana::kIsQE, kAzure+7)},
}
const Cut kIsQE
Definition: TruthCuts.cxx:104
enum BeamMode kOrange
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
const Cut kIsRes
Definition: TruthCuts.cxx:111
const Cut kIsDIS
Definition: TruthCuts.cxx:118
const Cut kIsDytmanMEC
Definition: TruthCuts.cxx:187
enum BeamMode kGreen

Definition at line 123 of file KinematicsHistos.C.

Referenced by MakeObservablesSpectra(), and MakeTruthSpectra().

const ana::Var kNonQEMECWgt
Initial value:
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
const Var kRPAWeightRES2017
Definition: GenieWeights.h:115
const Var kRescaleHighWDIS
Definition: GenieWeights.h:316
const Var kFixNonres1Pi
Definition: GenieWeights.h:127

Definition at line 133 of file KinematicsHistos.C.

Referenced by MakeObservablesSpectra(), and MakeTruthSpectra().

const std::set<std::string> KNOWN_DATASETS
Initial value:
{
"test",
"prod3",
"prod4",
}

Definition at line 56 of file KinematicsHistos.C.

Referenced by IOManager::GetLoader().

const ana::Var kVisMuHadE([](const caf::SRProxy *sr){return kMuE(sr)+ana::kNumuHadVisE(sr);})
const std::unordered_map<std::string, ana::Var> MECQE_WGTS
Initial value:
{
{ "MINERvA-1p1h", ana::kMINERvA_Wgt_QE},
{ "MINERvA-2p2h", ana::kMINERvA_Wgt_MEC},
{ "MINERvA-2p2hnp", ana::kMINERvA_Wgt_MECNP},
{ "MINERvA-2p2hpp", ana::kMINERvA_Wgt_MECPP},
}
const Var kMINERvA_Wgt_MEC
Definition: GenieWeights.h:232
const Var kEmpiricalMECtoValenciaMECWgt
Definition: GenieWeights.h:190
const Var kMINERvA_Wgt_MECPP
Definition: GenieWeights.h:240
const Var kMEC2018QElikeWgt
Definition: GenieWeights.h:159
const Var kEmpiricalMECWgt2018
See kEmpiricalMECWgt2018_NT.
Definition: GenieWeights.h:254
const Var kRPAWeightCCQE2018
Definition: GenieWeights.h:96
const Var kRescaleMAQE
Definition: GenieWeights.h:61
const Var kMINERvA_Wgt_QE
Definition: GenieWeights.h:228
const Var kMEC2018RESlikeWgt
Definition: GenieWeights.h:163
const Var kMINERvA_Wgt_MECNP
Definition: GenieWeights.h:236
const Var kDytmanMEC_Disable
Definition: TruthVars.h:15

Definition at line 145 of file KinematicsHistos.C.

Referenced by MakeObservablesSpectra(), and MakeTruthSpectra().

const std::unordered_map<std::string, ana::HistAxis> OBSERVABLE_HIST_AXES
Initial value:
{
{"Ehad", {"Reco E_{had} (GeV)", ana::Binning::Simple(50, 0., 2.), kHadE}},
{"EhadVis", {"Visible E_{had} (GeV)", ana::Binning::Simple(50, 0., 1.), ana::kNumuHadVisE}},
{"Emu", {"Reco E_{#mu} (GeV)", ana::Binning::Simple(50, 0., 3.), kMuE}},
{"Enu", {"Reco E_{#nu} (GeV)", ana::Binning::Simple(50, 0., 4.), kCCE}},
{"Emu+EHadVis", {"Reco E_{#mu} + Vis. E_{had} (GeV)", ana::Binning::Simple(50, 0., 4.), kVisMuHadE}},
{"RecoQ0", {"Reco 'q_{0}' = E_{had,vis} (GeV)", ana::Binning::Simple(50, 0., 2.), ana::kNumuHadVisE}},
{"RecoQ2", {"Reco Q^{2} (GeV^{2})", ana::Binning::Simple(50, 0., 2.), ana::kRecoQ2}},
{"RecoQmag", {"Reco |#vec{q}| = #sqrt{Q^{2}+q_{0}^{2}} (GeV)", ana::Binning::Simple(50, 0., 2.), ana::kRecoQmag}},
{"RecoW", {"Reco W (GeV)", ana::Binning::Simple(50, 0., 2.), ana::kRecoW}},
}
const Var kHadE
Definition: NumuVars.h:23
const ana::Var kRecoQ2([](const caf::SRProxy *sr){const double M_mu_sqrd=util::sqr(0.1056);double E_mu=kMuE(sr);double p_mu=sqrt(util::sqr(E_mu)-M_mu_sqrd);return 2 *kCCE(sr)*(E_mu-p_mu *kCosNumi(sr))-M_mu_sqrd;})
Reconstructed four-momentum transfer invariant (Q^2)
Definition: NumuVars.h:146
const Var kRecoQmag([](const caf::SRProxy *sr){return sqrt(kRecoQ2(sr)+util::sqr(kHadE(sr)));})
Reconstructed three-momentum transfer.
Definition: NumuVars.h:149
const Var kNumuHadVisE([](const caf::SRProxy *sr){return kNumuHadCalE(sr)+kNumuHadTrkE(sr);})
Definition: NumuVars.h:124
const ana::Var kVisMuHadE([](const caf::SRProxy *sr){return kMuE(sr)+ana::kNumuHadVisE(sr);})
const Var kCCE
Definition: NumuVars.h:21
const Var kRecoW([](const caf::SRProxy *sr){const double M_p=0.938272;double WSq=M_p *M_p+2 *M_p *(kCCE(sr)-kMuE(sr))-kRecoQ2(sr);if(WSq > 0) return sqrt(WSq);else return-5.;})
Reconstructed invariant mass (W)
Definition: NumuVars.h:152
const Var kMuE
Definition: NumuVars.h:22
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107

Definition at line 102 of file KinematicsHistos.C.

Referenced by MakeObservablesSpectra().

const std::unordered_map<std::string, std::unordered_map<std::string, ana::Cut> > SLICE_BREAKDOWNS
Initial value:
{
{ "RecoQ0",
{
{"+q3=0-0.1", Q3CutFactory(0, 0.1) },
{"+q3=0.1-0.2", Q3CutFactory(0.1, 0.2) },
{"+q3=0.2-0.3", Q3CutFactory(0.2, 0.3) },
{"+q3=0.3-0.4", Q3CutFactory(0.3, 0.4) },
{"+q3=0.4-0.5", Q3CutFactory(0.4, 0.5) },
{"+q3=0.5-0.6", Q3CutFactory(0.5, 0.6) },
{"+q3=0.6-0.7", Q3CutFactory(0.6, 0.7) },
{"+q3=0.7-0.8", Q3CutFactory(0.7, 0.8) },
{"+q3=0.8-0.9", Q3CutFactory(0.8, 0.9) },
{"+q3=0.9-1.0", Q3CutFactory(0.9, 1.0) },
}
}
}
ana::Cut Q3CutFactory(float lb, float ub)

Definition at line 158 of file KinematicsHistos.C.

Referenced by MakeObservablesSpectra().

const std::unordered_map<std::string, ana::HistAxis> TRUTH_HIST_AXES
Initial value:
{
{"TrueEnu", {"True E_{#nu} (GeV)", ana::Binning::Simple(50, 0., 4.), ana::kTrueQ0}},
{"TrueQ2", { "True Q^{2} (GeV^{2})", ana::Binning::Simple(50, 0., 2.), ana::kTrueQ2}},
{"TrueQmag", {"True |#vec{q}| (GeV)", ana::Binning::Simple(50, 0., 2.), ana::kTrueQ3}},
{"TrueQ0", {"True q_{0} (GeV)", ana::Binning::Simple(50, 0., 2.), ana::kTrueQ0}},
{"TrueW", {"True W (GeV)", ana::Binning::Simple(50, 0., 2.), ana::kTrueW}},
}
const Var kTrueQ0
Definition: TruthVars.h:32
const Var kTrueQ2
Definition: TruthVars.h:27
const Var kTrueQ3
Definition: TruthVars.h:38
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
const Var kTrueW
Definition: TruthVars.h:22

Definition at line 114 of file KinematicsHistos.C.

Referenced by MakeTruthSpectra().