All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
sim::DumpGTruth Class Reference
Inheritance diagram for sim::DumpGTruth:

Classes

struct  Config
 Collection of configuration parameters for the module. More...
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 Type to enable module parameters description by art. More...
 

Public Member Functions

 DumpGTruth (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpGTruth (DumpGTruth const &)=delete
 
 DumpGTruth (DumpGTruth &&)=delete
 
DumpGTruthoperator= (DumpGTruth const &)=delete
 
DumpGTruthoperator= (DumpGTruth &&)=delete
 
virtual void analyze (art::Event const &event) override
 

Static Public Member Functions

template<typename Handle >
static std::string productName (Handle const &handle)
 Returns the name of the product in the form "module_instance_process". More...
 

Private Attributes

std::vector< art::InputTag > fInputTruth
 Name of GTruth data products. More...
 
std::string fOutputCategory
 Name of the stream for output. More...
 
bool bAllTruth = false
 Whether to process all GTruth collections. More...
 
bool bAllowNoTruth = false
 Whether to forgive when no truth is present. More...
 

Detailed Description

Definition at line 38 of file DumpGTruth_module.cc.

Member Typedef Documentation

using sim::DumpGTruth::Parameters = art::EDAnalyzer::Table<Config>

Type to enable module parameters description by art.

Definition at line 67 of file DumpGTruth_module.cc.

Constructor & Destructor Documentation

sim::DumpGTruth::DumpGTruth ( Parameters const &  config)
explicit

Configuration-checking constructor.

Definition at line 100 of file DumpGTruth_module.cc.

101  : EDAnalyzer(config)
102  , fInputTruth()
103  , fOutputCategory(config().OutputCategory())
104  , bAllTruth(!config().InputTruth(fInputTruth)) // true if InputTruth omitted
105  , bAllowNoTruth(config().AllowNoTruth())
106 {
107  if (!bAllTruth && bAllowNoTruth) {
108  throw art::Exception(art::errors::Configuration)
109  << "'AllowNoTruth' is only allowed if no 'InputTruth' is specified.\n";
110  }
111 }
std::string fOutputCategory
Name of the stream for output.
bool bAllTruth
Whether to process all GTruth collections.
std::vector< art::InputTag > fInputTruth
Name of GTruth data products.
bool bAllowNoTruth
Whether to forgive when no truth is present.
sim::DumpGTruth::DumpGTruth ( DumpGTruth const &  )
delete
sim::DumpGTruth::DumpGTruth ( DumpGTruth &&  )
delete

Member Function Documentation

void sim::DumpGTruth::analyze ( art::Event const &  event)
overridevirtual

Definition at line 115 of file DumpGTruth_module.cc.

115  {
116 
117  //
118  // prepare the data products to be dumped
119  //
120  struct ProductInfo_t {
121  using Thruths_t = std::vector<simb::GTruth>;
122  Thruths_t const* truths;
123  std::string name;
124 
125  ProductInfo_t(art::Handle<Thruths_t> const& handle)
126  : truths(handle.provenance()->isPresent()? handle.product(): nullptr)
127  , name(sim::DumpGTruth::productName(handle))
128  {}
129  ProductInfo_t(art::ValidHandle<Thruths_t> const& handle)
130  : truths(handle.product()), name(sim::DumpGTruth::productName(handle))
131  {}
132 
133  }; // ProductInfo_t
134 
135  std::vector<ProductInfo_t> AllTruths;
136  if (bAllTruth) {
137  //std::vector<art::Handle<std::vector<simb::GTruth>>> handles;
138  //event.getManyByType(handles);
139  auto handles = event.getMany<std::vector<simb::GTruth>>();
140  std::copy(handles.begin(), handles.end(), std::back_inserter(AllTruths));
141  }
142  else {
143  for (auto const& inputTag: fInputTruth) {
144  AllTruths.emplace_back
145  (event.getValidHandle<std::vector<simb::GTruth>>(inputTag));
146  } // for
147  }
148 
149  //
150  // sanity check
151  //
152  if (AllTruths.empty() && !bAllowNoTruth) {
153  throw art::Exception(art::errors::ProductNotFound)
154  << "No GENIE truth found to be dumped!\n";
155  }
156 
157  //
158  // print an introduction
159  //
160  unsigned int const nTruths = std::accumulate(
161  AllTruths.begin(), AllTruths.end(), 0U,
162  [](unsigned int total, auto const& info)
163  { return total + (info.truths? info.truths->size(): 0); }
164  );
165 
166  if (bAllTruth) {
167  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
168  << " contains " << nTruths << " GENIE truth blocks in "
169  << AllTruths.size() << " collections";
170  }
171  else if (AllTruths.size() == 1) {
172  mf::LogVerbatim(fOutputCategory) << "Event " << event.id();
173  }
174  else {
175  mf::LogVerbatim(fOutputCategory) << "Dumping " << nTruths
176  << " GENIE truth blocks from " << AllTruths.size()
177  << " collections in event " << event.id();
178  }
179 
180  //
181  // dump data product by data product
182  //
183  for (ProductInfo_t const& truths_info: AllTruths) {
184 
185  auto const* truths = truths_info.truths;
186  std::string productName = truths_info.name;
187 
188  if (!truths) {
189  mf::LogVerbatim(fOutputCategory)
190  << "Data product '" << productName
191  << "' has been dropped. No information available.";
192  }
193 
194  if (AllTruths.size() > 1) {
195  mf::LogVerbatim(fOutputCategory)
196  << "Data product '" << productName
197  << "' contains " << truths->size() << " truth blocks:";
198  }
199  else if (truths->size() > 1) {
200  mf::LogVerbatim(fOutputCategory)
201  << truths->size() << " truth blocks:";
202  }
203 
204  //
205  // dump each GENIE truth in the data product
206  //
207  unsigned int iTruth = 0;
208  for (auto const& truth: *truths) {
209 
210  mf::LogVerbatim log (fOutputCategory);
211 
212  if (truths->size() > 1) log << "(#" << iTruth << ") ";
213  sim::dump::DumpGTruth(log, truth, " ", "");
214 
215  //
216  // update counters
217  //
218  ++iTruth;
219 
220  } // for each truth in data product
221 
222  } // for truth data products
223 
224  //
225  // all done
226  //
227 
228 } // sim::DumpGTruth::analyze()
void DumpGTruth(Stream &&out, simb::GTruth const &truth, std::string indent, std::string firstIndent)
Dumps the content of the GENIE truth in the output stream.
Definition: MCDumpers.h:379
static std::string productName(Handle const &handle)
Returns the name of the product in the form &quot;module_instance_process&quot;.
std::string fOutputCategory
Name of the stream for output.
bool bAllTruth
Whether to process all GTruth collections.
DumpGTruth(Parameters const &config)
Configuration-checking constructor.
T copy(T const &v)
then echo fcl name
std::vector< art::InputTag > fInputTruth
Name of GTruth data products.
bool bAllowNoTruth
Whether to forgive when no truth is present.
DumpGTruth& sim::DumpGTruth::operator= ( DumpGTruth const &  )
delete
DumpGTruth& sim::DumpGTruth::operator= ( DumpGTruth &&  )
delete
template<typename Handle >
std::string sim::DumpGTruth::productName ( Handle const &  handle)
static

Returns the name of the product in the form "module_instance_process".

Definition at line 233 of file DumpGTruth_module.cc.

233  {
234  auto const* prov = handle.provenance();
235  return prov->moduleLabel()
236  + '_' + prov->productInstanceName()
237  + '_' + prov->processName()
238  ;
239 } // sim::DumpGTruth::productName()

Member Data Documentation

bool sim::DumpGTruth::bAllowNoTruth = false
private

Whether to forgive when no truth is present.

Definition at line 92 of file DumpGTruth_module.cc.

bool sim::DumpGTruth::bAllTruth = false
private

Whether to process all GTruth collections.

Definition at line 91 of file DumpGTruth_module.cc.

std::vector<art::InputTag> sim::DumpGTruth::fInputTruth
private

Name of GTruth data products.

Definition at line 89 of file DumpGTruth_module.cc.

std::string sim::DumpGTruth::fOutputCategory
private

Name of the stream for output.

Definition at line 90 of file DumpGTruth_module.cc.


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