LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
EventWeight_module.cc
Go to the documentation of this file.
1 // Class: EventWeight
3 // Module Type: producer
4 // File: EventWeight_module.cc
5 //
6 // Generated at Fri Mar 20 09:36:11 2015 by Zarko Pavlovic using artmod
7 // from cetpkgsupport v1_08_04.
8 //
9 // Ported from uboonecode to larsim on Feb 14 2018 by Marco Del Tutto
11 
23 #include "fhiclcpp/ParameterSet.h"
25 
26 #include <memory>
27 #include <iostream>
28 #include <iomanip>
29 
35 
37 
38 namespace evwgh {
39 
40  class EventWeight : public art::EDProducer {
41  public:
42  explicit EventWeight(fhicl::ParameterSet const & p);
43  // The destructor generated by the compiler is fine for classes
44  // without bare pointers or other resource use.
45 
46  // Plugins should not be copied or assigned.
47  EventWeight(EventWeight const &) = delete;
48  EventWeight(EventWeight &&) = delete;
49  EventWeight & operator = (EventWeight const &) = delete;
50  EventWeight & operator = (EventWeight &&) = delete;
51 
52  // Required functions.
53  void produce(art::Event & e) override;
54 
55  //Optional functions.
56  void endJob() override;
57 
58  private:
59 
61 
62  //std::map<std::string, Weight_t*> fWeightCalcMap;
63  std::string fGenieModuleLabel;
64 
65  };
66 
68  // Initialize member data here.
69  {
70 
71  size_t n_func = _wgt_manager.Configure(p, *this);//p.get<fhicl::ParameterSet> ("WeightManagerConfig"), *this);
72 
73  fGenieModuleLabel = p.get<std::string> ("genie_module_label", "generator");
74 
75  // Call appropriate produces<>() functions here.
76  if ( n_func > 0 )
77  produces<std::vector<MCEventWeight> >();
78 
79  }
80 
82  {
83  // Implementation of required member function here.
84  std::unique_ptr<std::vector<MCEventWeight> > mcwghvec(new std::vector<MCEventWeight>);
85 
86  // Get the MC generator information out of the event
87  // these are all handles to mc information.
89  std::vector<art::Ptr<simb::MCTruth> > mclist;
90 
91  // Actually go and get the stuff
92  e.getByLabel(fGenieModuleLabel, mcTruthHandle);
93  if (!mcTruthHandle.isValid()) {
94  throw cet::exception(__FUNCTION__) << "Can't find GENIE module label with name " << fGenieModuleLabel << std::endl;
95  }
96  art::fill_ptr_vector(mclist, mcTruthHandle);
97 
98 
99  //
100  // Loop over all neutrinos in this event
101  //
102  for (unsigned int inu = 0; inu < mclist.size(); inu++)
103  {
104 
105  MCEventWeight mcwgh = _wgt_manager.Run(e, inu);
106 
107  (*mcwghvec).push_back(mcwgh);
108 
109  }
110 
111  e.put(std::move(mcwghvec));
112  }
113 
115  {
116 
117  // Get the map from sting to Weight_t from the manager
118  std::map<std::string, Weight_t*> weightCalcMap = _wgt_manager.GetWeightCalcMap();
119 
120  std::stringstream job_summary;
121  job_summary << std::setprecision(2);
122  for (int i=1; i <= 110 ;i++) job_summary << "=";
123  job_summary << std::endl;
124  job_summary << std::setw(20) << "WeightCalc"
125  << std::setw(15) << "Type"
126  << std::setw(15) << "#RW neutrinos"
127  << std::setw(15) << "#Multisims"
128  << std::setw(15) << "Min"
129  << std::setw(15) << "Max"
130  << std::setw(15) << "Avg"
131  << std::endl;
132  for (int i=1; i <= 110; i++) job_summary << "=";
133  job_summary << std::endl;
134  for (auto it = weightCalcMap.begin(); it!=weightCalcMap.end(); it++) {
135  job_summary << std::setw(20) << it->first
136  << std::setw(15) << (it->second->fWeightCalcType)
137  << std::setw(15) << (it->second->fNcalls)
138  << std::setw(15) << (it->second->fNmultisims)
139  << std::setw(15) << (it->second->fMinWeight)
140  << std::setw(15) << (it->second->fMaxWeight)
141  << std::setw(15) << (it->second->fAvgWeight)
142  << std::endl;
143  }
144  for (int i=1; i<=110; i++) job_summary << "=";
145  job_summary << std::endl;
146  mf::LogInfo("") << job_summary.str();
147  }
148 
149 } // namespace
150 
void produce(art::Event &e) override
size_t Configure(fhicl::ParameterSet const &cfg, art::EngineCreator &ec)
Configuration function.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fGenieModuleLabel
Allows to interface to EventWeight calculators.
EventWeight & operator=(EventWeight const &)=delete
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void endJob() override
std::map< std::string, Weight_t * > GetWeightCalcMap()
Returns the map between calculator name and Weight_t product.
Definition: WeightManager.h:79
T get(std::string const &key) const
Definition: ParameterSet.h:231
WeightManager _wgt_manager
EventWeight(fhicl::ParameterSet const &p)
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:34
MCEventWeight Run(art::Event &e, const int inu)
Core function (previous call to Configure is needed)
Tools and modules for checking out the basics of the Monte Carlo.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33