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::DumpMCTruth Class Reference
Inheritance diagram for sim::DumpMCTruth:

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

 DumpMCTruth (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpMCTruth (DumpMCTruth const &)=delete
 
 DumpMCTruth (DumpMCTruth &&)=delete
 
DumpMCTruthoperator= (DumpMCTruth const &)=delete
 
DumpMCTruthoperator= (DumpMCTruth &&)=delete
 
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 MCTruth data products. More...
 
std::string fOutputCategory
 Name of the stream for output. More...
 
bool bAllTruth = false
 Whether to process all MCTruth collections. More...
 
unsigned int fPointsPerLine
 trajectory points per output line More...
 

Detailed Description

Definition at line 37 of file DumpMCTruth_module.cc.

Member Typedef Documentation

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

Type to enable module parameters description by art.

Definition at line 65 of file DumpMCTruth_module.cc.

Constructor & Destructor Documentation

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

Configuration-checking constructor.

Definition at line 102 of file DumpMCTruth_module.cc.

103  : EDAnalyzer(config)
104  , fInputTruth()
105  , fOutputCategory(config().OutputCategory())
106  , bAllTruth(!config().InputTruth(fInputTruth)) // true if InputTruth omitted
107  , fPointsPerLine(config().PointsPerLine())
108  {}
unsigned int fPointsPerLine
trajectory points per output line
bool bAllTruth
Whether to process all MCTruth collections.
std::string fOutputCategory
Name of the stream for output.
std::vector< art::InputTag > fInputTruth
Name of MCTruth data products.
sim::DumpMCTruth::DumpMCTruth ( DumpMCTruth const &  )
delete
sim::DumpMCTruth::DumpMCTruth ( DumpMCTruth &&  )
delete

Member Function Documentation

void sim::DumpMCTruth::analyze ( art::Event const &  event)
override

Definition at line 112 of file DumpMCTruth_module.cc.

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

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

Definition at line 236 of file DumpMCTruth_module.cc.

236  {
237  auto const* prov = handle.provenance();
238  return prov->moduleLabel()
239  + '_' + prov->productInstanceName()
240  + '_' + prov->processName()
241  ;
242 } // sim::DumpMCTruth::productName()

Member Data Documentation

bool sim::DumpMCTruth::bAllTruth = false
private

Whether to process all MCTruth collections.

Definition at line 90 of file DumpMCTruth_module.cc.

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

Name of MCTruth data products.

Definition at line 88 of file DumpMCTruth_module.cc.

std::string sim::DumpMCTruth::fOutputCategory
private

Name of the stream for output.

Definition at line 89 of file DumpMCTruth_module.cc.

unsigned int sim::DumpMCTruth::fPointsPerLine
private

trajectory points per output line

Definition at line 92 of file DumpMCTruth_module.cc.


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