LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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::DataViewImpl::getByLabel(), art::DataViewImpl::getManyByType(), 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  mclists.clear();
32 
33  if ( fInputModuleLabels.size()==0) {
35  // std::cout << "evt.getManyByType" << std::endl;
36  } else {
37  mclists.resize(fInputModuleLabels.size());
38  for (size_t i=0; i<fInputModuleLabels.size(); ++i) {
40  //std::cout << "evt.getByLabel " << fInputModuleLabels[i] << std::endl;
41  }
42  }
43 
44  //std::cerr << "evg::GENIEDumper::analyze got stuff ---------------- "
45  // << evt.id() << std::endl;
46 
47  for (size_t mcl = 0; mcl < mclists.size(); ++mcl) {
49  if ( ! mclistHandle.isValid() ) {
50  // std::cerr << "not valid mcl=" << mcl << "---------------- " << std::endl;
51  continue;
52  }
53  // processName, moduleLabel, instance (productInstanceName?)
54  /*
55  std::cout << " mclistHandle processName '"
56  << mclistHandle.provenance()->processName() // top of fcl file
57  << "' moduleLabel '"
58  << mclistHandle.provenance()->moduleLabel()
59  << "' productInstanceName '"
60  << mclistHandle.provenance()->productInstanceName()
61  << "'"
62  << std::endl;
63  */
64 
65  std::string handleLabel = mclistHandle.provenance()->moduleLabel();
66  outlabels.push_back(handleLabel);
67  /*
68  std::cerr << "mcl=" << mcl << " '" << handleLabel << "' ---------------- " << std::endl;
69  */
70 
71  // loop over mctruths in a list
72  for(size_t nmc = 0; nmc < mclistHandle->size(); ++nmc) {
73  art::Ptr<simb::MCTruth> mct(mclistHandle, nmc);
74 
75  std::pair<int,int> ipair(mcl,nmc);
76  indices.insert(ipair);
77 
84  }
85 
86  }
87 
88  indx_itr = indices.begin();
89  nmctruth = (int)(indices.size());
90  //std::cout << ".... found nmctruth " << nmctruth
91  // << " nlabels " << outlabels.size()
92  // << std::endl;
93 
94 }
std::vector< art::Handle< std::vector< simb::MCTruth > > > mclists
std::vector< std::string > outlabels
bool isValid() const
Definition: Handle.h:190
const simb::GTruth * thisGTruth
Provenance const * provenance() const
Definition: Handle.h:204
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
std::vector< std::string > const & fInputModuleLabels
const bsim::NuChoice * thisNuChoice
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
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
virtual evgb::MCTruthAndFriendsItr::~MCTruthAndFriendsItr ( )
inlinevirtual

Definition at line 38 of file MCTruthAndFriendsItr.h.

References Next().

38 { ; }

Member Function Documentation

const bsim::Dk2Nu* evgb::MCTruthAndFriendsItr::GetDk2Nu ( ) const
inline

Definition at line 44 of file MCTruthAndFriendsItr.h.

References thisDk2Nu.

44 { return thisDk2Nu; }
const simb::GTruth* evgb::MCTruthAndFriendsItr::GetGTruth ( ) const
inline

Definition at line 42 of file MCTruthAndFriendsItr.h.

References thisGTruth.

42 { return thisGTruth; }
const simb::GTruth * thisGTruth
std::string evgb::MCTruthAndFriendsItr::GetLabel ( ) const
inline

Definition at line 47 of file MCTruthAndFriendsItr.h.

References thisLabel.

47 { return thisLabel; }
const simb::MCFlux* evgb::MCTruthAndFriendsItr::GetMCFlux ( ) const
inline

Definition at line 43 of file MCTruthAndFriendsItr.h.

References thisMCFlux.

43 { return thisMCFlux; }
const simb::MCFlux * thisMCFlux
const simb::MCTruth* evgb::MCTruthAndFriendsItr::GetMCTruth ( ) const
inline

Definition at line 41 of file MCTruthAndFriendsItr.h.

References thisMCTruth.

41 { return thisMCTruth; }
const simb::MCTruth * thisMCTruth
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 96 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 ~MCTruthAndFriendsItr().

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

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: