LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
evgb::MCTruthAndFriendsItr Class Reference

#include "MCTruthAndFriendsItr.h"

Public Member Functions

 MCTruthAndFriendsItr (art::Event const &evtIn, std::vector< std::string > const &labels)
 
virtual ~MCTruthAndFriendsItr ()
 
bool Next ()
 
const simb::MCTruthGetMCTruth () const
 
const simb::GTruthGetGTruth () const
 
const simb::MCFluxGetMCFlux () const
 
const bsim::Dk2Nu * GetDk2Nu () const
 
const bsim::NuChoice * GetNuChoice () const
 
std::string GetLabel () const
 

Private Attributes

art::Event const & evt
 
std::vector< std::string > const & fInputModuleLabels
 
std::vector< art::Handle< std::vector< simb::MCTruth > > > mclists
 
std::set< std::pair< int, int > > indices
 
std::set< std::pair< int, int > >::const_iterator indx_itr
 
std::vector< std::string > outlabels
 
int nmctruth
 
int imctruth
 
const simb::MCTruththisMCTruth
 
const simb::GTruththisGTruth
 
const simb::MCFluxthisMCFlux
 
const bsim::Dk2Nu * thisDk2Nu
 
const bsim::NuChoice * thisNuChoice
 
std::string thisLabel
 

Detailed Description

Definition at line 32 of file MCTruthAndFriendsItr.h.

Constructor & Destructor Documentation

evgb::MCTruthAndFriendsItr::MCTruthAndFriendsItr ( art::Event const &  evtIn,
std::vector< std::string > const &  labels 
)

std::cout << "+++ mcl " << mcl << "[" << mclists.size() << "] " << "nmc " << nmc << "[" << mclistHandle->size() << "] " << std::endl; std::cout << *(mct.get()) << std::endl;

Definition at line 15 of file MCTruthAndFriendsItr.cxx.

References evt, fInputModuleLabels, art::ProductRetriever::getByLabel(), art::ProductRetriever::getMany(), indices, indx_itr, art::Handle< T >::isValid(), mclists, nmctruth, outlabels, and art::Handle< T >::provenance().

17  : evt(evtIn)
18  , fInputModuleLabels(labels)
19  , indx_itr(indices.begin())
20  , nmctruth(0)
21  , imctruth(-1)
22  , thisMCTruth(0)
23  , thisGTruth(0)
24  , thisMCFlux(0)
25  , thisDk2Nu(0)
26  , thisNuChoice(0)
27  , thisLabel("")
28 {
29 
30  // look for any existing MCTruth info in this event
31  if ( fInputModuleLabels.size()==0) {
32  mclists = evt.getMany<std::vector<simb::MCTruth>>();
33  // std::cout << "evt.getManyByType" << std::endl;
34  } else {
35  mclists.resize(fInputModuleLabels.size());
36  for (size_t i=0; i<fInputModuleLabels.size(); ++i) {
38  //std::cout << "evt.getByLabel " << fInputModuleLabels[i] << std::endl;
39  }
40  }
41 
42  //std::cerr << "evg::GENIEDumper::analyze got stuff ---------------- "
43  // << evt.id() << std::endl;
44 
45  for (size_t mcl = 0; mcl < mclists.size(); ++mcl) {
47  if ( ! mclistHandle.isValid() ) {
48  // std::cerr << "not valid mcl=" << mcl << "---------------- " << std::endl;
49  continue;
50  }
51  // processName, moduleLabel, instance (productInstanceName?)
52  /*
53  std::cout << " mclistHandle processName '"
54  << mclistHandle.provenance()->processName() // top of fcl file
55  << "' moduleLabel '"
56  << mclistHandle.provenance()->moduleLabel()
57  << "' productInstanceName '"
58  << mclistHandle.provenance()->productInstanceName()
59  << "'"
60  << std::endl;
61  */
62 
63  std::string handleLabel = mclistHandle.provenance()->moduleLabel();
64  outlabels.push_back(handleLabel);
65  /*
66  std::cerr << "mcl=" << mcl << " '" << handleLabel << "' ---------------- " << std::endl;
67  */
68 
69  // loop over mctruths in a list
70  for(size_t nmc = 0; nmc < mclistHandle->size(); ++nmc) {
71  art::Ptr<simb::MCTruth> mct(mclistHandle, nmc);
72 
73  std::pair<int,int> ipair(mcl,nmc);
74  indices.insert(ipair);
75 
82  }
83 
84  }
85 
86  indx_itr = indices.begin();
87  nmctruth = (int)(indices.size());
88  //std::cout << ".... found nmctruth " << nmctruth
89  // << " nlabels " << outlabels.size()
90  // << std::endl;
91 
92 }
std::vector< art::Handle< std::vector< simb::MCTruth > > > mclists
std::vector< std::string > outlabels
bool isValid() const noexcept
Definition: Handle.h:203
const simb::GTruth * thisGTruth
Provenance const * provenance() const
Definition: Handle.h:217
std::vector< std::string > const & fInputModuleLabels
const bsim::NuChoice * thisNuChoice
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::set< std::pair< int, int > > indices
const simb::MCFlux * thisMCFlux
const simb::MCTruth * thisMCTruth
std::set< std::pair< int, int > >::const_iterator indx_itr
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
virtual evgb::MCTruthAndFriendsItr::~MCTruthAndFriendsItr ( )
inlinevirtual

Definition at line 38 of file MCTruthAndFriendsItr.h.

References Next().

38 { ; }

Member Function Documentation

const simb::GTruth* evgb::MCTruthAndFriendsItr::GetGTruth ( ) const
inline

Definition at line 42 of file MCTruthAndFriendsItr.h.

References thisGTruth.

Referenced by evg::GenieOutput::analyze().

42 { return thisGTruth; }
const simb::GTruth * thisGTruth
const simb::MCFlux* evgb::MCTruthAndFriendsItr::GetMCFlux ( ) const
inline

Definition at line 43 of file MCTruthAndFriendsItr.h.

References thisMCFlux.

Referenced by evg::GenieOutput::analyze().

43 { return thisMCFlux; }
const simb::MCFlux * thisMCFlux
const bsim::NuChoice* evgb::MCTruthAndFriendsItr::GetNuChoice ( ) const
inline

Definition at line 45 of file MCTruthAndFriendsItr.h.

References thisNuChoice.

45 { return thisNuChoice; }
const bsim::NuChoice * thisNuChoice
bool evgb::MCTruthAndFriendsItr::Next ( )

std::cout << "imctruth " << std::setw(3) << imctruth << " [" << indx_handle << "," << indx_within << "]" << " hvMCTruth.isValid() " << hvMCTruth.isValid() << " '" << outlabels[indx_handle] << "' " << std::endl;

Definition at line 94 of file MCTruthAndFriendsItr.cxx.

References evt, art::Ptr< T >::get(), imctruth, indx_itr, mclists, nmctruth, outlabels, thisDk2Nu, thisGTruth, thisLabel, thisMCFlux, thisMCTruth, and thisNuChoice.

Referenced by evg::GenieOutput::analyze(), evwgh::PPFXThinMesonWeightCalc::GetWeight(), evwgh::PPFXMIPPKaonWeightCalc::GetWeight(), evwgh::PPFXWeightCalc::GetWeight(), evwgh::PPFXTotAbsorpWeightCalc::GetWeight(), evwgh::PPFXThinPionWeightCalc::GetWeight(), evwgh::PPFXThinNucWeightCalc::GetWeight(), evwgh::PPFXThinNucAWeightCalc::GetWeight(), evwgh::PPFXOtherWeightCalc::GetWeight(), evwgh::PPFXMIPPPionWeightCalc::GetWeight(), evwgh::PPFXThinKaonWeightCalc::GetWeight(), evwgh::PPFXTargAttenWeightCalc::GetWeight(), evwgh::PPFXThinNeutronPionWeightCalc::GetWeight(), evwgh::PPFXCVWeightCalc::GetWeight(), and ~MCTruthAndFriendsItr().

95 {
96  ++imctruth; // started at -1, so first call to Next() prepares us for indx=0
97  thisMCTruth = 0;
98  thisGTruth = 0;
99  thisMCFlux = 0;
100  thisDk2Nu = 0;
101  thisNuChoice = 0;
102  //std::cerr << "Next() called ... moved to imctruth " << imctruth << std::endl;
103  if ( imctruth >= nmctruth ) return false;
104 
105  size_t indx_handle = (*indx_itr).first;
106  size_t indx_within = (*indx_itr).second;
107 
108  thisLabel = outlabels[indx_handle];
109 
110  art::Handle< std::vector<simb::MCTruth> > hvMCTruth = mclists[indx_handle];
111 
120  thisMCTruth = &(hvMCTruth->at(indx_within));
121 
122  // inefficient ... should only need to do this bit for every new
123  // Handle ...
124 
125  //art::FindOneP<recob::Hit> findSPToHits(fSpacePoints,evt,fSpacePointLabel);
126  //const art::Ptr<recob::Hit> hit = findSPToHits.at(iSP);
127 
128  try {
129  art::FindOneP<simb::GTruth> qgtruth(hvMCTruth,evt,outlabels[indx_handle]);
130  const art::Ptr<simb::GTruth> gtruthptr = qgtruth.at(indx_within);
131  thisGTruth = gtruthptr.get();
132  }
133  catch (...) {
134  // std::cerr << "no GTruth for this handle" << std::endl;
135  }
136 
137  try {
138  art::FindOneP<simb::MCFlux> qmcflux(hvMCTruth,evt,outlabels[indx_handle]);
139  const art::Ptr<simb::MCFlux> mcfluxptr = qmcflux.at(indx_within);
140  thisMCFlux = mcfluxptr.get();
141  }
142  catch (...) {
143  // std::cerr << "no MCFlux for this handle" << std::endl;
144  }
145 
146  try {
147  art::FindOneP<bsim::Dk2Nu> qdk2nu(hvMCTruth,evt,outlabels[indx_handle]);
148  const art::Ptr<bsim::Dk2Nu> dk2nuptr = qdk2nu.at(indx_within);
149  thisDk2Nu = dk2nuptr.get();
150  }
151  catch (...) {
152  // std::cerr << "no bsim::Dk2NU for this handle" << std::endl;
153  }
154 
155  try {
156  art::FindOneP<bsim::NuChoice> qnuchoice(hvMCTruth,evt,outlabels[indx_handle]);
157  const art::Ptr<bsim::NuChoice> nuchoiceptr = qnuchoice.at(indx_within);
158  thisNuChoice = nuchoiceptr.get();
159  }
160  catch (...) {
161  // std::cerr << "no bsim::NuChoice for this handle" << std::endl;
162  }
163 
164  //std::cerr << "Next() called ... seeing " << thisMCTruth
165  // << " " << thisGTruth << " " << thisMCFlux << std::endl;
166 
167  // so user code looks like
168  // evgb::MCTruthAndFriendsItr mcitr(evt,labels);
169  // while ( mcitr.Next() ) {
170  // const simb::MCTruth* amctruth = mcitr.GetMCTruth();
171  // const simb::GTruth* agtruth = mcitr.GetGTruth();
172  //...
173 
174  /*
175  // loop over lists
176  try {
177  //art::FindOneP<simb::GTruth> QueryG(mclistHandle,evt,handleLabel);
178  }
179  catch (art::Exception) {
180  //std::cerr << "no GTruth for " << handleLabel << std::endl;
181  }
182  */
183 
184  // move the iterator on
185  ++indx_itr;
186  return true;
187 }
std::vector< art::Handle< std::vector< simb::MCTruth > > > mclists
std::vector< std::string > outlabels
const simb::GTruth * thisGTruth
const bsim::NuChoice * thisNuChoice
const simb::MCFlux * thisMCFlux
const simb::MCTruth * thisMCTruth
std::set< std::pair< int, int > >::const_iterator indx_itr
T const * get() const
Definition: Ptr.h:138
Definition: fwd.h:26

Member Data Documentation

art::Event const& evgb::MCTruthAndFriendsItr::evt
private

Definition at line 52 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr(), and Next().

std::vector<std::string> const& evgb::MCTruthAndFriendsItr::fInputModuleLabels
private

Definition at line 53 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr().

int evgb::MCTruthAndFriendsItr::imctruth
private

Definition at line 62 of file MCTruthAndFriendsItr.h.

Referenced by Next().

std::set<std::pair<int,int> > evgb::MCTruthAndFriendsItr::indices
private

Definition at line 57 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr().

std::set<std::pair<int,int> >::const_iterator evgb::MCTruthAndFriendsItr::indx_itr
private

Definition at line 58 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr(), and Next().

std::vector< art::Handle< std::vector<simb::MCTruth> > > evgb::MCTruthAndFriendsItr::mclists
private

Definition at line 55 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr(), and Next().

int evgb::MCTruthAndFriendsItr::nmctruth
private

Definition at line 61 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr(), and Next().

std::vector<std::string> evgb::MCTruthAndFriendsItr::outlabels
private

Definition at line 59 of file MCTruthAndFriendsItr.h.

Referenced by MCTruthAndFriendsItr(), and Next().

const bsim::Dk2Nu* evgb::MCTruthAndFriendsItr::thisDk2Nu
private

Definition at line 67 of file MCTruthAndFriendsItr.h.

Referenced by GetDk2Nu(), and Next().

const simb::GTruth* evgb::MCTruthAndFriendsItr::thisGTruth
private

Definition at line 65 of file MCTruthAndFriendsItr.h.

Referenced by GetGTruth(), and Next().

std::string evgb::MCTruthAndFriendsItr::thisLabel
private

Definition at line 69 of file MCTruthAndFriendsItr.h.

Referenced by GetLabel(), and Next().

const simb::MCFlux* evgb::MCTruthAndFriendsItr::thisMCFlux
private

Definition at line 66 of file MCTruthAndFriendsItr.h.

Referenced by GetMCFlux(), and Next().

const simb::MCTruth* evgb::MCTruthAndFriendsItr::thisMCTruth
private

Definition at line 64 of file MCTruthAndFriendsItr.h.

Referenced by GetMCTruth(), and Next().

const bsim::NuChoice* evgb::MCTruthAndFriendsItr::thisNuChoice
private

Definition at line 68 of file MCTruthAndFriendsItr.h.

Referenced by GetNuChoice(), and Next().


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