LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
print_genie_weights.C File Reference
#include <iostream>
#include <string>
#include "larcoreobj/SimpleTypesAndConstants/geo_types.h"

Go to the source code of this file.

Functions

const std::string genie_producer_label ("generator")
 
const std::string eventweight_producer_label ("genieeventweightTest")
 
void print_weights (const std::string &filename)
 

Function Documentation

const std::string eventweight_producer_label ( "genieeventweightTest"  )

Referenced by print_weights().

const std::string genie_producer_label ( "generator"  )

Referenced by print_weights().

void print_weights ( const std::string &  filename)

Definition at line 15 of file print_genie_weights.C.

References simb::MCParticle::E(), eventweight_producer_label(), evwgh::MCEventWeight::fWeight, genie_producer_label(), simb::MCTruth::GetNeutrino(), simb::MCNeutrino::Nu(), and w.

16 {
17 
18  std::vector<std::string> filenames{filename};
19 
20  gallery::Event ev(filenames);
21 
22  size_t event_count = 1;
23  for (ev.toBegin(); !ev.atEnd(); ++ev) {
24 
25  std::cout << "art event " << event_count << '\n';
26 
27  // Use the GENIE producer label here
28  auto mctruth_handle = ev.getValidHandle<std::vector<simb::MCTruth>>(genie_producer_label);
29  auto gtruth_handle = ev.getValidHandle<std::vector<simb::GTruth>>(genie_producer_label);
30 
31  // Use the EventWeight producer label here
32  auto weights_handle =
33  ev.getValidHandle<std::vector<evwgh::MCEventWeight>>(eventweight_producer_label);
34 
35  // Loop through these objects for each neutrino vertex in the event
36  for (size_t v = 0u; v < mctruth_handle->size(); ++v) {
37 
38  const simb::MCTruth& mc = mctruth_handle->at(v);
39  const simb::GTruth& gt = gtruth_handle->at(v);
40  const evwgh::MCEventWeight& mc_weights = weights_handle->at(v);
41 
42  // Extract desired information
43  const auto& nu = mc.GetNeutrino();
44  if (nu.Nu().NumberTrajectoryPoints() > 0) {
45  double E_nu = nu.Nu().E(0);
46  bool cc = (nu.CCNC() == 0);
47  if (cc)
48  std::cout << "CC";
49  else
50  std::cout << "NC";
51 
52  int mode = nu.Mode();
53  if (mode == 0) {
54  if (cc)
55  std::cout << "QE";
56  else
57  std::cout << "EL";
58  }
59  else if (mode == 1)
60  std::cout << "RES";
61  else if (mode == 2)
62  std::cout << "DIS";
63  else if (mode == 3)
64  std::cout << "COH";
65  else if (mode == 10)
66  std::cout << "MEC";
67  else
68  std::cout << " other";
69  std::cout << " interaction with neutrino energy = " << E_nu << " GeV\n";
70  }
71 
72  // Loop over all of the weights in the MCEventWeight object
73  std::cout << "Weights\n";
74  for (const auto& pair : mc_weights.fWeight) {
75  std::string knob_name = pair.first;
76  std::vector<double> weights = pair.second;
77 
78  std::cout << " " << knob_name << ":\n";
79  for (size_t u = 0u; u < weights.size(); ++u) {
80  double w = weights.at(u);
81  std::cout << " universe #" << u << " has weight = " << w << '\n';
82  }
83  }
84  }
85 
86  ++event_count;
87  }
88 }
double E(const int i=0) const
Definition: MCParticle.h:234
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
std::map< std::string, std::vector< double > > fWeight
Definition: MCEventWeight.h:9
Event generator information.
Definition: MCTruth.h:32
Float_t w
Definition: plot.C:20