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

Public Types

using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 AnalyzeWeighters (fhicl::ParameterSet const &p)
 
 AnalyzeWeighters (AnalyzeWeighters const &)=delete
 
 AnalyzeWeighters (AnalyzeWeighters &&)=delete
 
AnalyzeWeightersoperator= (AnalyzeWeighters const &)=delete
 
AnalyzeWeightersoperator= (AnalyzeWeighters &&)=delete
 
void analyze (art::Event const &e) override
 
void reconfigure (fhicl::ParameterSet const &p)
 
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 Weights ()
 

Private Attributes

std::string fWeighter
 
std::unique_ptr< fnex::InputPointfInitialGuessInputPoint
 
art::ServiceHandle< art::TFileServicetfs
 
TH1 * hSigmahistograms [30]
 

Detailed Description

Definition at line 40 of file AnalyzeWeighters_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::AnalyzeWeighters::AnalyzeWeighters ( fhicl::ParameterSet const &  p)
explicit

Definition at line 67 of file AnalyzeWeighters_module.cc.

References reconfigure().

68  :
69  EDAnalyzer(p) // ,
70  // More initializers here.
71 {
72  this->reconfigure(p);
73 
74  return;
75 }
const char * p
Definition: xmltok.h:285
void reconfigure(fhicl::ParameterSet const &p)
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
fnex::AnalyzeWeighters::AnalyzeWeighters ( AnalyzeWeighters const &  )
delete
fnex::AnalyzeWeighters::AnalyzeWeighters ( AnalyzeWeighters &&  )
delete

Member Function Documentation

void fnex::AnalyzeWeighters::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 77 of file AnalyzeWeighters_module.cc.

References make_mec_shifts_plots::canvas, om::cout, e, allTimeWatchdog::endl, energy, fInitialGuessInputPoint, genie::utils::style::Format(), fWeighter, hSigmahistograms, fnex::ShifterAndWeighter::InitShiftsAndWeightsToUse(), fnex::ShifterAndWeighter::Instance(), makeTrainCVSamples::int, novadaq::cnv::kFARDET, fnex::kNu_RecoE, fnex::kNuE_CVN, fnex::kNuECC, fnex::kNuESelectionLowPID, fnex::kSwap, fnex::kTrueCCNC, fnex::kTrueIntType, fnex::kTruePDG, fnex::kTruePDGOrig, make_mec_shifts_plots::legend, LOG_VERBATIM, art::TFileDirectory::make(), make_pair(), fetch_tb_beamline_files::md, nevents, fnex::ShifterAndWeighter::SetCurrentVals(), tfs, and fnex::ShifterAndWeighter::Weight().

78 {
79  int nevents = 12; //Number of events. 12 events for 12 bin. 1 event per bin
80  int n_sigmas = 3; //Set number of sigmas that you want to make histograms to.
81  float pull = 0.0; //Initial Shift
82  float pull_increment = 0.5; //Increment in shift
83  double energy = 0.; //Energy initialization
84  double eventweight = 0.; //weight initialization
85 
86  //Canvas for storing all histograms
87  gStyle->SetOptStat("");
88  TCanvas* canvas = tfs->make<TCanvas>("canvas", "Weights for different Sigma shifts", 800, 800);
89  canvas->cd();
90  canvas->SetLeftMargin(0.20);
91 
92  //Legends for different histograms
93  TLegend* legend = new TLegend(0.65, 0.63, 0.88, 0.88);
94  legend ->SetBorderSize(0);
95  legend ->SetFillStyle(0);
96  legend ->SetTextSize(0.04);
97 
98  //Metadata: used by EventWeight function
99  fnex::MetaData md(true,
101  fnex::kSwap,
103  fnex::kNuECC,
104  "3b");
105 
107 
108  int Nsigmas = (int)n_sigmas/pull_increment;
109 
110  for(int i_sigma = 0; i_sigma < Nsigmas; ++i_sigma){
111 
112  //Make histograms
113  hSigmahistograms[i_sigma] = tfs->make<TH1F>(TString::Format("sigma_%2.2f", pull), ";E_{#nu} (GeV); Systematic. Weight Values", 12, 0, 3);
114  hSigmahistograms[i_sigma] ->SetTitle(TString::Format("Sigma_%2.2f", pull) );
115  hSigmahistograms[i_sigma] ->SetLineColor(kBlack+i_sigma);
116  hSigmahistograms[i_sigma] ->SetLineWidth(2);
117 
118  //Systematic pull used from the initial guess input point
119  ParameterDetMap pSystematicPulls = fInitialGuessInputPoint->SystematicPulls();
120 
121  //Print keys
122  for(auto pd: pSystematicPulls)
123  std::cout << "Keys are: " << pd.first.first << std::endl;
124 
125  //Set Systematic Sigma values here
127  if(pSystematicPulls.count(tempPairFar) != 0){
128  std::cout << fWeighter << " is the correct key." << std::endl;
129  pSystematicPulls[tempPairFar] = pull;
130  }
131  else std::cout << fWeighter << " is not the correct key" << std::endl;
132 
133  //New input point for every sigma shift value
134  //Initial Guess Input Point is used to make a new input point for each Sigma value
135  InputPoint newPoint(fInitialGuessInputPoint->ParameterSpaceLocation(),
136  pSystematicPulls,
137  fInitialGuessInputPoint->FixedParameters(),
138  fInitialGuessInputPoint->FixedSystematics());
139 
141 
142  //double parVal = newPoint.ParameterValue(std::make_pair("RadCorrNueWgt", md.detector));
143 
144  //loop over events
145  for(int e = 0; e < nevents; ++e){
146 
147  //Make a fake event here
148  fnex::EventPtr event(new fnex::Event);
149 
150  //Set energies for a new fake event
151  energy = (1. + double(e))*0.25 - 0.125;
152 
153  //Set some variable for fake event here
154  event->dataVals = std::make_unique<fnex::DataVarVals>();
155  event->mcVals = std::make_unique<fnex::MCVarVals >();
156 
157 // event->dataVals->set_val_at(fnex::kLep_RecoE, energy);
158 // event->dataVals->set_val_at(fnex::kHad_RecoE, 0. );
159  event->dataVals->set_val_at(fnex::kNu_RecoE, energy);
160  event->mcVals ->set_val_at(fnex::kTruePDGOrig, 14 );
161  event->mcVals ->set_val_at(fnex::kTruePDG, 14 );
162  event->mcVals ->set_val_at(fnex::kTrueCCNC, 0. );
163  event->mcVals ->set_val_at(fnex::kTrueIntType, 1000 );
164  event->dataVals->set_val_at(fnex::kNuE_CVN, 0.8 );
165 
166  //Get the value of the weight for the weighter
167  // if(event->mcVals->val_at(fnex::kTrueCCNC) == 1 &&
168  // event->mcVals->val_at(fnex::kTruePDG ) == 12 )
169  // eventweight = 1.0 + 0.02 * parVal;
170  // else eventweight = 1.0;
171  eventweight = fnex::ShifterAndWeighter::Instance()->Weight(event, md);
172  //eventweight = fnex::ShifterAndWeighter::Instance()->TotalWeightFromWeighters();
173 
174  //Fill and Draw histograms
175  hSigmahistograms[i_sigma]->Fill(energy, eventweight);
176  hSigmahistograms[i_sigma]->Draw("HIST same");
177  LOG_VERBATIM("AnalyzeWeighters")
178  << "Event energy set: "
179  << energy
180  << " Sigma: "
181  << pull
182  << " Weight: "
183  << eventweight;
184 
185  }//end of loop over different energies
186 
187  //Add legend entry for each histogram here
188  legend ->AddEntry(hSigmahistograms[i_sigma], TString::Format("%2.2f #sigma", pull), "l");
189 
190  //Increment systematic pull term here
191  pull += pull_increment;
192 
193  }//end of loop over different sigma values
194 
195  //Set user defined axis range and draw legend here.
196  //hSigmahistograms[0]->GetYaxis()->SetRangeUser(0, 1.5);
197  hSigmahistograms[0]->SetTitle(fWeighter.c_str());
198  hSigmahistograms[0]->GetXaxis()->CenterTitle();
199  hSigmahistograms[0]->GetXaxis()->SetDecimals();
200  hSigmahistograms[0]->GetYaxis()->CenterTitle();
201  hSigmahistograms[0]->GetYaxis()->SetDecimals();
202  hSigmahistograms[0]->GetYaxis()->SetTitleOffset(1.5);
203 
204 
205  legend ->Draw();
206 
207  // Save the canvas to file
208  canvas ->Update();
209  canvas ->Write();
210 
211  return;
212 }
void SetCurrentVals(fnex::InputPoint const &curPoint)
static const unsigned char kNu_RecoE
Definition: VarVals.h:36
static const unsigned char kNuE_CVN
Definition: VarVals.h:32
art::ServiceHandle< art::TFileService > tfs
void InitShiftsAndWeightsToUse(fnex::InputPoint const &curPoint, std::string CalibFilename="FNEX/data/calibration/CalibrationSystematics2018.root")
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
static ShifterAndWeighter * Instance()
Int_t nevents
Definition: SimpleIterate.C:25
static const unsigned char kTruePDGOrig
Definition: VarVals.h:46
static const unsigned char kTrueCCNC
Definition: VarVals.h:44
Far Detector at Ash River, MN.
double Weight(fnex::EventPtr const &curEvent, fnex::MetaData const &md, fnex::WeightType_t const wgtType=kAllWgt)
double energy
Definition: plottest35.C:25
static const unsigned char kTrueIntType
Definition: VarVals.h:45
std::unordered_map< ParameterDet, double, ParameterDetHasher > ParameterDetMap
Definition: Constants.h:63
OStream cout
Definition: OStream.cxx:6
T * make(ARGS...args) const
std::shared_ptr< Event > EventPtr
Definition: Event.h:50
std::pair< std::string, novadaq::cnv::DetId > ParameterDet
Definition: Constants.h:38
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
#define LOG_VERBATIM(category)
Float_t e
Definition: plot.C:35
std::unique_ptr< fnex::InputPoint > fInitialGuessInputPoint
static const unsigned char kTruePDG
Definition: VarVals.h:43
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
CurrentProcessingContext const* art::EDAnalyzer::currentContext ( ) const
protectedinherited
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
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
AnalyzeWeighters& fnex::AnalyzeWeighters::operator= ( AnalyzeWeighters const &  )
delete
AnalyzeWeighters& fnex::AnalyzeWeighters::operator= ( AnalyzeWeighters &&  )
delete
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
std::string const& art::EventObserverBase::processName ( ) const
inlineinherited
void fnex::AnalyzeWeighters::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 215 of file AnalyzeWeighters_module.cc.

References fnex::DEFINE_ART_MODULE(), fInitialGuessInputPoint, fWeighter, fhicl::ParameterSet::get(), and string.

Referenced by AnalyzeWeighters().

216 {
217  // Implementation of optional member function here.
218  fWeighter = p.get< std::string >("Weighter" );
219  fInitialGuessInputPoint = std::make_unique<InputPoint>(p.get< fhicl::ParameterSet>("InitialGuessInputPoint") );
220 }
const char * p
Definition: xmltok.h:285
std::unique_ptr< fnex::InputPoint > fInitialGuessInputPoint
enum BeamMode string
void art::EventObserverBase::registerProducts ( MasterProductRegistry ,
ProductDescriptions ,
ModuleDescription const &   
)
inlineinherited

Definition at line 33 of file EventObserverBase.h.

References string.

36  {}
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 &)
void fnex::AnalyzeWeighters::Weights ( )
private
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

std::unique_ptr<fnex::InputPoint> fnex::AnalyzeWeighters::fInitialGuessInputPoint
private

Definition at line 59 of file AnalyzeWeighters_module.cc.

Referenced by analyze(), and reconfigure().

std::string fnex::AnalyzeWeighters::fWeighter
private

Definition at line 58 of file AnalyzeWeighters_module.cc.

Referenced by analyze(), and reconfigure().

TH1* fnex::AnalyzeWeighters::hSigmahistograms[30]
private

Definition at line 62 of file AnalyzeWeighters_module.cc.

Referenced by analyze().

art::ServiceHandle<art::TFileService> fnex::AnalyzeWeighters::tfs
private

Definition at line 60 of file AnalyzeWeighters_module.cc.

Referenced by analyze().


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