CVNValidation_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNValidation_module.cc
3 // \brief Analyzer module to make some standard validation plots
4 // of the CVN performance
5 // \author Leigh Whitehead - leigh.howard.whitehead@cern.ch
6 ////////////////////////////////////////////////////////////////////////
7 
8 // C/C++ includes
9 #include <iostream>
10 #include <sstream>
11 
12 // ROOT includes
13 #include "TTree.h"
14 #include "TH2F.h"
15 
16 // Framework includes
21 #include "art_root_io/TFileDirectory.h"
22 #include "art_root_io/TFileService.h"
24 #include "fhiclcpp/ParameterSet.h"
27 
28 // LArSoft includes
32 
34 
36 
37 
38 namespace cvn {
39  class CVNValidation : public art::EDAnalyzer {
40  public:
41 
42  explicit CVNValidation(fhicl::ParameterSet const& pset);
44 
45  void analyze(const art::Event& evt) override;
46  void reconfigure(const fhicl::ParameterSet& pset);
47  void beginJob() override;
48  void endJob() override;
49 
50  private:
51 
56 
57  TTree* fValidTree;
58 
59  /// Tree branch variables
60  /// Neutrino flavour probabilities
61  float fNumuProb;
62  float fNueProb;
63  float fNutauProb;
64  float fNCProb;
65  /// Reco energy for numu and nue probabilities
66  float fNumuEnergy;
67  float fNueEnergy;
68  /// Truth information
69  int fPDG; // We set this to 0 for NC
70 
71  };
72 
73  //.......................................................................
75  : EDAnalyzer(pset)
76  {
77  this->reconfigure(pset);
78  }
79 
80  //......................................................................
82  { }
83 
84  //......................................................................
86  {
87  fResultLabel = pset.get<std::string>("CVNResultLabel");
88  fTruthLabel = pset.get<std::string>("TruthLabel");
89  fNumuEnergyLabel = pset.get<std::string> ("NumuEnergyLabel");
90  fNueEnergyLabel = pset.get<std::string> ("NueEnergyLabel");
91  }
92 
93  //......................................................................
95  {
96 
98 
99  fValidTree = tfs->make<TTree>("CVNOutput", "CVN Output");
100  fValidTree->Branch("pNumu",&fNumuProb,"fNumuProb/F");
101  fValidTree->Branch("pNue",&fNueProb,"fNueProb/F");
102  fValidTree->Branch("pNutau",&fNutauProb,"fNutauProb/F");
103  fValidTree->Branch("pNC",&fNCProb,"fNCProb/F");
104  fValidTree->Branch("numuEnergy",&fNumuEnergy,"fNumuEnergy/F");
105  fValidTree->Branch("nueEnergy",&fNueEnergy,"fNueEnergy/F");
106  fValidTree->Branch("pdg",&fPDG,"fPDG/I");
107  }
108 
109  //......................................................................
111  {
112 
113  }
114 
115  //......................................................................
117  {
118 
119  // Get the CVN results
120  auto cvnResults = evt.getValidHandle<std::vector<cvn::Result>>(fResultLabel);
121  if(!cvnResults.isValid()) return;
122  if(cvnResults->size()==0) return;
123 
124  // Get the truth information
125  auto truthInfo = evt.getValidHandle<std::vector<simb::MCTruth>>(fTruthLabel);
126  if(!truthInfo.isValid()) return;
127  if(truthInfo->size()==0) return;
128  if(!truthInfo->at(0).NeutrinoSet()) return;
129 
130  // Get the energy results
131  auto numuEnergy = evt.getValidHandle<dune::EnergyRecoOutput>(fNumuEnergyLabel);
132  auto nueEnergy = evt.getValidHandle<dune::EnergyRecoOutput>(fNueEnergyLabel);
133  if(!numuEnergy.isValid() || !nueEnergy.isValid()) return;
134 
135  // Fill the CVN flavour branches
136  fNumuProb = cvnResults->at(0).GetNumuProbability();
137  fNueProb = cvnResults->at(0).GetNueProbability();
138  fNutauProb = cvnResults->at(0).GetNutauProbability();
139  fNCProb = cvnResults->at(0).GetNCProbability();
140  // Reconstructed energy
141  fNumuEnergy = numuEnergy->fNuLorentzVector.E();
142  fNueEnergy = nueEnergy->fNuLorentzVector.E();
143  // PDG
144  fPDG = truthInfo->at(0).GetNeutrino().Nu().PdgCode();
145  if(truthInfo->at(0).GetNeutrino().CCNC() == simb::kNC){
146  fPDG = 0;
147  }
148 
149  fValidTree->Fill();
150 
151  }
152 
154 
155 } // end namespace cvn
156 ////////////////////////////////////////////////////////////////////////
157 
158 
159 
160 
161 
162 
163 
std::string string
Definition: nybbler.cc:12
void analyze(const art::Event &evt) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Utility class for truth labels.
Particle class.
void reconfigure(const fhicl::ParameterSet &pset)
Result for CVN.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void beginJob() override
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
int fPDG
Truth information.
float fNumuEnergy
Reco energy for numu and nue probabilities.
TCEvent evt
Definition: DataStructs.cxx:7
CVNValidation(fhicl::ParameterSet const &pset)