Public Member Functions | Private Attributes | List of all members
cvn::GCNGraphROOT Class Reference
Inheritance diagram for cvn::GCNGraphROOT:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 GCNGraphROOT (fhicl::ParameterSet const &p)
 
 GCNGraphROOT (GCNGraphROOT const &)=delete
 
 GCNGraphROOT (GCNGraphROOT &&)=delete
 
GCNGraphROOToperator= (GCNGraphROOT const &)=delete
 
GCNGraphROOToperator= (GCNGraphROOT &&)=delete
 
void reconfigure (fhicl::ParameterSet const &p)
 
void beginSubRun (art::SubRun const &sr) override
 Beginning of a subrun, make a new file. More...
 
void endSubRun (art::SubRun const &sr) override
 End of a subrun, write all events to a ROOT file. More...
 
void analyze (art::Event const &e) override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string fGraphModuleLabel
 Name of graph producer module. More...
 
std::string fGraphInstanceLabel
 Name of graph instance. More...
 
std::string fTruthLabel
 Name of truth producer module. More...
 
std::string fOutputName
 ROOT output filename. More...
 
std::string fTreeName
 ROOT tree name. More...
 
bool fSaveEventTruth
 Whether to save event-level truth information. More...
 
bool fSaveParticleFlow
 Whether to include particle flow information. More...
 
std::vector< std::vector< float > > fPosition
 Node positions. More...
 
std::vector< std::vector< float > > fFeatures
 Node features. More...
 
std::vector< std::vector< float > > fGroundTruth
 Node ground truth. More...
 
std::vector< unsigned int > fEvent
 Event numbers. More...
 
bool fIsCC
 Whether the neutrino interaction is charged current. More...
 
float fNuEnergy
 True neutrino energy. More...
 
float fLepEnergy
 True lepton energy. More...
 
float fNuDirX
 X component of true neutrino direction. More...
 
float fNuDirY
 Y component of true neutrino direction. More...
 
float fNuDirZ
 Z component of true neutrino direction. More...
 
std::map< unsigned int, unsigned int > fParticleFlow
 Particle flow map. More...
 
TFile * fFile
 Output ROOT file. More...
 
TTree * fTree
 ROOT tree for writing to file. More...
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 33 of file GCNGraphROOT_module.cc.

Constructor & Destructor Documentation

cvn::GCNGraphROOT::GCNGraphROOT ( fhicl::ParameterSet const &  p)
explicit

Definition at line 79 of file GCNGraphROOT_module.cc.

80  : EDAnalyzer{p} {
81  this->reconfigure(p);
82  }
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
p
Definition: test.py:223
void reconfigure(fhicl::ParameterSet const &p)
cvn::GCNGraphROOT::GCNGraphROOT ( GCNGraphROOT const &  )
delete
cvn::GCNGraphROOT::GCNGraphROOT ( GCNGraphROOT &&  )
delete

Member Function Documentation

void cvn::GCNGraphROOT::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 96 of file GCNGraphROOT_module.cc.

96  {
97 
98  // Get the graphVector
100  std::vector<art::Ptr<GCNGraph>> graphVector;
101  if (!e.getByLabel(fGraphModuleLabel, fGraphInstanceLabel, graphHandle)) {
103  << "Could not find GCNGraph vector with module label "
104  << fGraphModuleLabel << " and instance label "
105  << fGraphInstanceLabel << "!" << std::endl;
106  }
107  art::fill_ptr_vector(graphVector, graphHandle);
108 
109  if (graphVector.size() > 1) throw art::Exception(art::errors::LogicError)
110  << "There shouldn't be more than one GCNGraph per producer per event,"
111  << " but here there are " << graphVector.size() << "." << std::endl;
112 
113  if (graphVector.empty()) return;
114 
115  // Empty vectors
116  fPosition.clear();
117  fFeatures.clear();
118  fGroundTruth.clear();
119 
120  // Loop over nodes and refill them
121  for (size_t itNode = 0; itNode < graphVector[0]->GetNumberOfNodes(); ++itNode) {
122  GCNGraphNode node = graphVector[0]->GetNode(itNode);
123  fPosition.push_back(node.GetPosition());
124  fFeatures.push_back(node.GetFeatures());
125  fGroundTruth.push_back(node.GetGroundTruth());
126  }
127 
128  fEvent = std::vector<unsigned int>({e.id().run(), e.id().subRun(), e.id().event()});
129 
130  // Event truth
131  if (fSaveEventTruth) {
132 
133  // Get MC truth
135  e.getByLabel(fTruthLabel, truthHandle);
136  if (!truthHandle.isValid() || truthHandle->size() != 1) {
138  << "Expected to find exactly one MC truth object!";
139  }
140  simb::MCNeutrino nutruth = truthHandle->at(0).GetNeutrino();
141 
142  // Fill variables
143  fIsCC = (nutruth.CCNC() == simb::kCC);
144  fNuEnergy = nutruth.Nu().E();
145  fLepEnergy = nutruth.Lepton().E();
146  fNuDirX = nutruth.Nu().Momentum().Vect().Unit().X();
147  fNuDirX = nutruth.Nu().Momentum().Vect().Unit().Y();
148  fNuDirX = nutruth.Nu().Momentum().Vect().Unit().Z();
149 
150  } // if saving event truth
151 
152  // Particle flow
153  if (fSaveParticleFlow) {
154 
155  // Get particle flow
157  e.getByLabel(fGraphModuleLabel, fGraphInstanceLabel, pfHandle);
158  if (!pfHandle.isValid() || pfHandle->size() != 1) {
160  << "Expected exactly one graph particle flow object.";
161  }
162  fParticleFlow = pfHandle->at(0).GetMap();
163 
164  } // if saving particle flow
165 
166  fTree->Fill();
167 
168  } // cvn::GCNGraphROOT::analyze
double E(const int i=0) const
Definition: MCParticle.h:232
int CCNC() const
Definition: MCNeutrino.h:148
TTree * fTree
ROOT tree for writing to file.
std::vector< std::vector< float > > fFeatures
Node features.
bool fSaveParticleFlow
Whether to include particle flow information.
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
bool fSaveEventTruth
Whether to save event-level truth information.
std::vector< std::vector< float > > fPosition
Node positions.
float fNuEnergy
True neutrino energy.
bool isValid() const
Definition: Handle.h:183
const double e
const simb::MCParticle & Lepton() const
Definition: MCNeutrino.h:147
std::string fTruthLabel
Name of truth producer module.
std::map< unsigned int, unsigned int > fParticleFlow
Particle flow map.
std::string fGraphModuleLabel
Name of graph producer module.
float fLepEnergy
True lepton energy.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
float fNuDirX
X component of true neutrino direction.
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:219
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:291
std::vector< std::vector< float > > fGroundTruth
Node ground truth.
Event generator information.
Definition: MCNeutrino.h:18
std::string fGraphInstanceLabel
Name of graph instance.
std::vector< unsigned int > fEvent
Event numbers.
bool fIsCC
Whether the neutrino interaction is charged current.
QTextStream & endl(QTextStream &s)
void cvn::GCNGraphROOT::beginSubRun ( art::SubRun const &  sr)
overridevirtual

Beginning of a subrun, make a new file.

Reimplemented from art::EDAnalyzer.

Definition at line 171 of file GCNGraphROOT_module.cc.

171  {
172 
173  // Open ROOT file
174  boost::uuids::random_generator generator;
175  boost::uuids::uuid uuid = generator();
176  std::ostringstream fileName;
177  fileName << fOutputName << "_" << uuid << ".root";
178  fFile = TFile::Open(fileName.str().c_str(), "recreate");
179 
180  fTree = new TTree(fTreeName.c_str(), fTreeName.c_str());
181  fTree->Branch("Position", &fPosition);
182  fTree->Branch("Features", &fFeatures);
183  fTree->Branch("GroundTruth", &fGroundTruth);
184  fTree->Branch("Event", &fEvent);
185 
186  if (fSaveEventTruth) {
187  fTree->Branch("IsCC", &fIsCC);
188  fTree->Branch("NuEnergy", &fNuEnergy);
189  fTree->Branch("LepEnergy", &fLepEnergy);
190  fTree->Branch("NuDirX", &fNuDirX);
191  fTree->Branch("NuDirY", &fNuDirY);
192  fTree->Branch("NuDirZ", &fNuDirZ);
193  } // If saving event truth
194 
195  if (fSaveParticleFlow) {
196  fTree->Branch("ParticleFlow", &fParticleFlow);
197  } // If saving particle flow
198 
199  } // function GCNGraphROOT::beginSubRun
TTree * fTree
ROOT tree for writing to file.
TFile * fFile
Output ROOT file.
std::vector< std::vector< float > > fFeatures
Node features.
bool fSaveParticleFlow
Whether to include particle flow information.
bool fSaveEventTruth
Whether to save event-level truth information.
float fNuDirZ
Z component of true neutrino direction.
std::vector< std::vector< float > > fPosition
Node positions.
float fNuEnergy
True neutrino energy.
std::map< unsigned int, unsigned int > fParticleFlow
Particle flow map.
generator
Definition: train.py:468
float fNuDirY
Y component of true neutrino direction.
float fLepEnergy
True lepton energy.
float fNuDirX
X component of true neutrino direction.
std::string fOutputName
ROOT output filename.
std::vector< std::vector< float > > fGroundTruth
Node ground truth.
std::vector< unsigned int > fEvent
Event numbers.
bool fIsCC
Whether the neutrino interaction is charged current.
std::string fTreeName
ROOT tree name.
void cvn::GCNGraphROOT::endSubRun ( art::SubRun const &  sr)
overridevirtual

End of a subrun, write all events to a ROOT file.

Reimplemented from art::EDAnalyzer.

Definition at line 202 of file GCNGraphROOT_module.cc.

202  {
203 
204  fFile->WriteTObject(fTree, fTreeName.c_str());
205  delete fFile;
206 
207  } // cvn::GCNGraphROOT::endSubRun
TTree * fTree
ROOT tree for writing to file.
TFile * fFile
Output ROOT file.
std::string fTreeName
ROOT tree name.
GCNGraphROOT& cvn::GCNGraphROOT::operator= ( GCNGraphROOT const &  )
delete
GCNGraphROOT& cvn::GCNGraphROOT::operator= ( GCNGraphROOT &&  )
delete
void cvn::GCNGraphROOT::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 84 of file GCNGraphROOT_module.cc.

84  {
85 
86  fGraphModuleLabel = p.get<std::string>("GraphModuleLabel");
87  fGraphInstanceLabel = p.get<std::string>("GraphInstanceLabel");
88  fTruthLabel = p.get<std::string>("TruthLabel"),
89  fOutputName = p.get<std::string>("OutputName");
90  fTreeName = p.get<std::string>("TreeName");
91  fSaveEventTruth = p.get<bool>("SaveEventTruth");
92  fSaveParticleFlow = p.get<bool>("SaveParticleFlow");
93 
94  } // cvn::GCNGraphROOT::reconfigure
std::string string
Definition: nybbler.cc:12
bool fSaveParticleFlow
Whether to include particle flow information.
bool fSaveEventTruth
Whether to save event-level truth information.
std::string fTruthLabel
Name of truth producer module.
std::string fGraphModuleLabel
Name of graph producer module.
p
Definition: test.py:223
std::string fOutputName
ROOT output filename.
std::string fGraphInstanceLabel
Name of graph instance.
std::string fTreeName
ROOT tree name.

Member Data Documentation

std::vector<unsigned int> cvn::GCNGraphROOT::fEvent
private

Event numbers.

Definition at line 62 of file GCNGraphROOT_module.cc.

std::vector<std::vector<float> > cvn::GCNGraphROOT::fFeatures
private

Node features.

Definition at line 59 of file GCNGraphROOT_module.cc.

TFile* cvn::GCNGraphROOT::fFile
private

Output ROOT file.

Definition at line 73 of file GCNGraphROOT_module.cc.

std::string cvn::GCNGraphROOT::fGraphInstanceLabel
private

Name of graph instance.

Definition at line 51 of file GCNGraphROOT_module.cc.

std::string cvn::GCNGraphROOT::fGraphModuleLabel
private

Name of graph producer module.

Definition at line 50 of file GCNGraphROOT_module.cc.

std::vector<std::vector<float> > cvn::GCNGraphROOT::fGroundTruth
private

Node ground truth.

Definition at line 60 of file GCNGraphROOT_module.cc.

bool cvn::GCNGraphROOT::fIsCC
private

Whether the neutrino interaction is charged current.

Definition at line 64 of file GCNGraphROOT_module.cc.

float cvn::GCNGraphROOT::fLepEnergy
private

True lepton energy.

Definition at line 66 of file GCNGraphROOT_module.cc.

float cvn::GCNGraphROOT::fNuDirX
private

X component of true neutrino direction.

Definition at line 67 of file GCNGraphROOT_module.cc.

float cvn::GCNGraphROOT::fNuDirY
private

Y component of true neutrino direction.

Definition at line 68 of file GCNGraphROOT_module.cc.

float cvn::GCNGraphROOT::fNuDirZ
private

Z component of true neutrino direction.

Definition at line 69 of file GCNGraphROOT_module.cc.

float cvn::GCNGraphROOT::fNuEnergy
private

True neutrino energy.

Definition at line 65 of file GCNGraphROOT_module.cc.

std::string cvn::GCNGraphROOT::fOutputName
private

ROOT output filename.

Definition at line 53 of file GCNGraphROOT_module.cc.

std::map<unsigned int, unsigned int> cvn::GCNGraphROOT::fParticleFlow
private

Particle flow map.

Definition at line 71 of file GCNGraphROOT_module.cc.

std::vector<std::vector<float> > cvn::GCNGraphROOT::fPosition
private

Node positions.

Definition at line 58 of file GCNGraphROOT_module.cc.

bool cvn::GCNGraphROOT::fSaveEventTruth
private

Whether to save event-level truth information.

Definition at line 55 of file GCNGraphROOT_module.cc.

bool cvn::GCNGraphROOT::fSaveParticleFlow
private

Whether to include particle flow information.

Definition at line 56 of file GCNGraphROOT_module.cc.

TTree* cvn::GCNGraphROOT::fTree
private

ROOT tree for writing to file.

Definition at line 74 of file GCNGraphROOT_module.cc.

std::string cvn::GCNGraphROOT::fTreeName
private

ROOT tree name.

Definition at line 54 of file GCNGraphROOT_module.cc.

std::string cvn::GCNGraphROOT::fTruthLabel
private

Name of truth producer module.

Definition at line 52 of file GCNGraphROOT_module.cc.


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