Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
fnex::SystematicsWeightTest Class Reference
Inheritance diagram for fnex::SystematicsWeightTest:
art::EDAnalyzer art::EventObserverBase art::Consumer art::EngineCreator

Public Types

using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 SystematicsWeightTest (fhicl::ParameterSet const &pset)
 
virtual ~SystematicsWeightTest ()=default
 
void beginJob () override
 
void beginRun (const art::Run &run) override
 
void beginSubRun (const art::SubRun &sr) override
 
void analyze (const art::Event &evt) override
 
void reconfigure (fhicl::ParameterSet const &p) override
 
void endSubRun (const art::SubRun &sr) override
 
void endRun (const art::Run &run) override
 
void endJob () override
 
std::string workerType () const
 
bool modifiesEvent () const
 
void registerProducts (MasterProductRegistry &, ProductDescriptions &, ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
art::Handle< art::TriggerResultsgetTriggerResults (Event const &e) const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
detail::CachedProducts & cachedProducts ()
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Member Functions

void CreateSpectra ()
 
void InitializeWeighters (fhicl::ParameterSet const &pset)
 
void MakePlots ()
 
void SavePlots ()
 

Private Attributes

std::unique_ptr< fnex::EventListManipulatorfManipulator
 helper object to work with event lists from TTrees More...
 
fnex::EventListMap fEventLists
 event lists More...
 
std::unordered_map< std::string, std::shared_ptr< fnex::Weighter > > fWeighters
 
std::unordered_map< fnex::MetaData, fnex::Spectrum, fnex::MetaDataHasherfSpectra
 
std::vector< std::stringfVarNames
 

Detailed Description

Definition at line 38 of file SystematicsWeightTest_module.cc.

Member Typedef Documentation

Definition at line 39 of file EDAnalyzer.h.

Definition at line 38 of file EDAnalyzer.h.

Constructor & Destructor Documentation

fnex::SystematicsWeightTest::SystematicsWeightTest ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 73 of file SystematicsWeightTest_module.cc.

References InitializeWeighters(), and reconfigure().

74  : art::EDAnalyzer(pset)
75  {
76  // do the necessary setup
77  this->reconfigure(pset);
78  this->InitializeWeighters(pset);
79  }
void reconfigure(fhicl::ParameterSet const &p) override
void InitializeWeighters(fhicl::ParameterSet const &pset)
virtual fnex::SystematicsWeightTest::~SystematicsWeightTest ( )
virtualdefault

Member Function Documentation

void fnex::SystematicsWeightTest::analyze ( const art::Event evt)
inlineoverride

Definition at line 49 of file SystematicsWeightTest_module.cc.

49 {};
void fnex::SystematicsWeightTest::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 82 of file SystematicsWeightTest_module.cc.

References CreateSpectra(), fEventLists, and fManipulator.

83  {
84  this->fEventLists = this->fManipulator->Deserialize(); // copy the event lists from the deserializer.
85 
86  mf::LogDebug("SystematicsWeightTest") << "Got " << this->fEventLists.size() << " event lists from the deserializer.";
87 
88  this->CreateSpectra();
89  }
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
fnex::EventListMap fEventLists
event lists
std::unique_ptr< fnex::EventListManipulator > fManipulator
helper object to work with event lists from TTrees
void fnex::SystematicsWeightTest::beginRun ( const art::Run run)
inlineoverride

Definition at line 47 of file SystematicsWeightTest_module.cc.

47 {};
void fnex::SystematicsWeightTest::beginSubRun ( const art::SubRun sr)
inlineoverride

Definition at line 48 of file SystematicsWeightTest_module.cc.

48 {};
detail::CachedProducts& art::EventObserverBase::cachedProducts ( )
inlineprotectedinherited

Definition at line 79 of file EventObserverBase.h.

References art::EventObserverBase::selectors_.

80  {
81  return selectors_;
82  }
detail::CachedProducts selectors_
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
void fnex::SystematicsWeightTest::CreateSpectra ( )
private

Definition at line 106 of file SystematicsWeightTest_module.cc.

References fEventLists, and fSpectra.

Referenced by beginJob().

107  {
108  for (auto & evListPair : this->fEventLists)
109  {
110  this->fSpectra.emplace(std::piecewise_construct,
111  std::make_tuple(evListPair.first),
112  std::make_tuple(evListPair.second)
113  );
114  }
115  } // SystematicsWeightTest::CreateSpectra()
std::unordered_map< fnex::MetaData, fnex::Spectrum, fnex::MetaDataHasher > fSpectra
fnex::EventListMap fEventLists
event lists
CurrentProcessingContext const* art::EDAnalyzer::currentContext ( ) const
protectedinherited
void fnex::SystematicsWeightTest::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 92 of file SystematicsWeightTest_module.cc.

References SavePlots().

93  {
94  this->SavePlots();
95  }
void fnex::SystematicsWeightTest::endRun ( const art::Run run)
inlineoverride

Definition at line 52 of file SystematicsWeightTest_module.cc.

References MakePlots().

52 {};
void fnex::SystematicsWeightTest::endSubRun ( const art::SubRun sr)
inlineoverride

Definition at line 51 of file SystematicsWeightTest_module.cc.

51 {};
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
art::Handle<art::TriggerResults> art::EventObserverBase::getTriggerResults ( Event const &  e) const
inlineinherited

Definition at line 61 of file EventObserverBase.h.

References art::detail::CachedProducts::getOneTriggerResults(), and art::EventObserverBase::selectors_.

62  {
64  }
detail::CachedProducts selectors_
art::Handle< art::TriggerResults > getOneTriggerResults(Event const &) const
Float_t e
Definition: plot.C:35
void fnex::SystematicsWeightTest::InitializeWeighters ( fhicl::ParameterSet const &  pset)
private

Definition at line 119 of file SystematicsWeightTest_module.cc.

References om::cout, allTimeWatchdog::endl, and fWeighters.

Referenced by SystematicsWeightTest().

120  {
121  StupidWeight_Linear * s = new StupidWeight_Linear; // this is leaked. in a real module you'd want to keep track of this guy
122  this->fWeighters.emplace("StupidLinearWgt", std::make_shared<fnex::Weighter>("StupidLinearWgt", s));
123  std::cout << " weight function address:" << this->fWeighters.at("StupidLinearWgt")->WeightFunctionObj() << std::endl;
124  }
const XML_Char * s
Definition: expat.h:262
std::unordered_map< std::string, std::shared_ptr< fnex::Weighter > > fWeighters
OStream cout
Definition: OStream.cxx:6
void fnex::SystematicsWeightTest::MakePlots ( )
private
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::EventObserverBase::modifiesEvent ( ) const
inlineinherited

Definition at line 25 of file EventObserverBase.h.

26  {
27  return false;
28  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
std::string const& art::EventObserverBase::processName ( ) const
inlineinherited
void fnex::SystematicsWeightTest::reconfigure ( fhicl::ParameterSet const &  p)
override

Definition at line 98 of file SystematicsWeightTest_module.cc.

References fManipulator, fVarNames, and fhicl::ParameterSet::get().

Referenced by SystematicsWeightTest().

99  {
100  this->fManipulator = std::make_unique<fnex::EventListManipulator>(pset);
101 
102  fVarNames = pset.get< std::vector<std::string> >("SpectrumVars");
103  }
std::vector< std::string > fVarNames
std::unique_ptr< fnex::EventListManipulator > fManipulator
helper object to work with event lists from TTrees
void art::EventObserverBase::registerProducts ( MasterProductRegistry ,
ProductDescriptions ,
ModuleDescription const &   
)
inlineinherited

Definition at line 33 of file EventObserverBase.h.

References string.

36  {}
void fnex::SystematicsWeightTest::SavePlots ( )
private

Definition at line 128 of file SystematicsWeightTest_module.cc.

References om::cout, fnex::DEFINE_ART_MODULE(), allTimeWatchdog::endl, MakeMiniprodValidationCuts::f, fSpectra, fWeighters, LOG_ERROR, sigma(), and string.

Referenced by endJob().

129  {
130  std::string varName = fnex::var::Nu_RecoE::Name();
131 
132  std::unique_ptr<TFile> f(TFile::Open("/nova/ana/users/jwolcott/scratch/weight_test_hists.root", "recreate"));
133  mf::LogDebug("SystematicsWeightTest") << "Got spectra for metadata:";
134  for (auto & specPair : this->fSpectra)
135  {
136  if (!specPair.first.isMC)
137  continue;
138 
139  mf::LogDebug("SystematicsWeightTest") << " " << specPair.first.ToString();
140 
141  const TH1F * hSpec = dynamic_cast<const TH1F*>(specPair.second.Histogram(varName));
142  TH1F * hnew = new TH1F(*hSpec);
143  hnew->SetName( (varName + "_" + specPair.first.ToString()).c_str() );
144  hnew->Write();
145 
146  for (auto & wgtPair : this->fWeighters)
147  {
148  const auto & wgtName = wgtPair.first;
149  auto & wgtr = wgtPair.second;
150  for (const auto sigma : {-0.5, 0.0, 1.0, 1.5})
151  {
152  //auto wgtFnPtr = dynamic_cast<fnex::SystematicsWeightFn*>(wgtr->WeightFunctionObj());
153  auto wgtFnPtr = dynamic_cast<fnex::InterpSystWgtFn*>(wgtr->WeightFunctionObj());
154  if (wgtFnPtr)
155  wgtFnPtr->SetSigma(sigma);
156  else
157  {
158  std::cout << " wgt function pointer address: " << wgtr->WeightFunctionObj() << std::endl;
159  LOG_ERROR("SystematicsWeightTest") << "Weight function pointer is of type: " << typeid(wgtr->WeightFunctionObj()).name();
160  throw cet::exception("SystematicsWeightTest::SavePlots(): couldn't set sigma for weight function pointer!");
161  }
162 
163  std::cout << " calculating weights for sigma = " << sigma << std::endl;
164  std::cout << " (weighter state = " << wgtr->State() << ")" << std::endl;
165  const TH1F * hSpecWgtd = dynamic_cast<const TH1F*>(specPair.second.Histogram(varName, {{}}, {{wgtr, wgtr->State()}}));
166  TH1F * hnewWgtd = new TH1F(*hSpecWgtd);
167  hnewWgtd->SetName( Form("%s_%s_%s_sigma=%.2f", varName.c_str(), specPair.first.ToString().c_str(), wgtName.c_str(), sigma) );
168  hnewWgtd->Write();
169  }
170  }
171  }
172  }
const XML_Char * name
Definition: expat.h:151
std::unordered_map< fnex::MetaData, fnex::Spectrum, fnex::MetaDataHasher > fSpectra
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
std::unordered_map< std::string, std::shared_ptr< fnex::Weighter > > fWeighters
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
#define LOG_ERROR(stream)
Definition: Messenger.h:129
enum BeamMode string
fhicl::ParameterSetID art::EventObserverBase::selectorConfig ( ) const
inlineinherited

Definition at line 56 of file EventObserverBase.h.

References art::EventObserverBase::selector_config_id_.

57  {
58  return selector_config_id_;
59  }
fhicl::ParameterSetID selector_config_id_
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited
bool art::EventObserverBase::wantAllEvents ( ) const
inlineinherited

Definition at line 46 of file EventObserverBase.h.

References art::EventObserverBase::wantAllEvents_.

Referenced by art::RootOutput::RootOutput().

47  {
48  return wantAllEvents_;
49  }
bool art::EventObserverBase::wantEvent ( Event const &  e)
inlineinherited

Definition at line 51 of file EventObserverBase.h.

References art::EventObserverBase::selectors_, and art::detail::CachedProducts::wantEvent().

52  {
53  return selectors_.wantEvent(e);
54  }
detail::CachedProducts selectors_
Float_t e
Definition: plot.C:35
bool wantEvent(Event const &)
std::string art::EDAnalyzer::workerType ( ) const
inlineinherited

Definition at line 109 of file EDAnalyzer.h.

References art::EDAnalyzer::currentContext().

110  {
111  return "WorkerT<EDAnalyzer>";
112  }

Member Data Documentation

fnex::EventListMap fnex::SystematicsWeightTest::fEventLists
private

event lists

Definition at line 63 of file SystematicsWeightTest_module.cc.

Referenced by beginJob(), and CreateSpectra().

std::unique_ptr<fnex::EventListManipulator> fnex::SystematicsWeightTest::fManipulator
private

helper object to work with event lists from TTrees

Definition at line 62 of file SystematicsWeightTest_module.cc.

Referenced by beginJob(), and reconfigure().

std::unordered_map<fnex::MetaData, fnex::Spectrum, fnex::MetaDataHasher> fnex::SystematicsWeightTest::fSpectra
private

Definition at line 65 of file SystematicsWeightTest_module.cc.

Referenced by CreateSpectra(), and SavePlots().

std::vector<std::string> fnex::SystematicsWeightTest::fVarNames
private

Definition at line 68 of file SystematicsWeightTest_module.cc.

Referenced by reconfigure().

std::unordered_map<std::string, std::shared_ptr<fnex::Weighter> > fnex::SystematicsWeightTest::fWeighters
private

Definition at line 64 of file SystematicsWeightTest_module.cc.

Referenced by InitializeWeighters(), and SavePlots().


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