Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
fnex::CovarianceMatrixMaker Class Reference
Inheritance diagram for fnex::CovarianceMatrixMaker:
art::ResultsProducer art::ProductRegistryHelper art::Consumer

Public Types

template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::PluginConfig, KeysToIgnore >
 

Public Member Functions

 CovarianceMatrixMaker (fhicl::ParameterSet const &pset)
 
virtual ~CovarianceMatrixMaker ()
 
 CovarianceMatrixMaker (CovarianceMatrixMaker const &)=delete
 
 CovarianceMatrixMaker (CovarianceMatrixMaker &&)=delete
 
CovarianceMatrixMakeroperator= (CovarianceMatrixMaker const &)=delete
 
CovarianceMatrixMakeroperator= (CovarianceMatrixMaker &&)=delete
 
void readResults (art::Results const &r) override
 
void writeResults (art::Results &r) override
 
void clear () override
 
void beginJob () override
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void doBeginJob ()
 
void doEndJob ()
 
void doBeginSubRun (SubRunPrincipal const &)
 
void doEndSubRun (SubRunPrincipal const &)
 
void doBeginRun (RunPrincipal const &)
 
void doEndRun (RunPrincipal const &)
 
void doEvent (EventPrincipal const &)
 
void doReadResults (ResultsPrincipal const &)
 
void doWriteResults (ResultsPrincipal &)
 
void doClear ()
 
void registerProducts (MasterProductRegistry &mpr, ProductDescriptions &producedProducts, ModuleDescription const &md)
 
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)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

template<class P >
void produces (std::string const &instanceName={})
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void setModuleDescription (ModuleDescription const &md)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Member Functions

void SetSystematicParameter (fnex::InputPoint &point)
 
void FillSpectrum (TH1D *spectrumBin, std::map< int, TH1D * > &spectraEnergy)
 

Private Attributes

std::unique_ptr< fnex::CovarianceBinUtilityfBinUtil
 useful functions for mapping bins to energy and back More...
 
art::ServiceHandle< art::TFileServicefTFS
 TFileService. More...
 
int fIterations
 number of iterations for picking sigmas More...
 
TRandom3 fRand
 RNG for picking the variation in parameters. More...
 
fhicl::ParameterSet fManipulatorParameters
 the fake point parameters More...
 
fnex::EventListMap fEventLists
 the lists of events we are going to use, data and MC More...
 
TH2D * fCovarianceMatrix
 Covariance matrix. More...
 
TH1D * fNominalSpectrum
 Nominal spectrum for each detector/beam/selection. More...
 
std::map< int, TH1D * > fNominalEnergySpectra
 Nominal energy spectrum for each detector/file/beam/selection. More...
 
TH1D * fShiftedSpectrum
 Shifted spectrum for each detector/beam/selection. More...
 
std::map< int, TH1D * > fShiftedEnergySpectra
 Shifted energy spectrum for each detector/file/beam/selection. More...
 
std::map< std::string, TH1D * > fShifts
 Shifts selected for each parameter adjusted. More...
 
fhicl::ParameterSet fInputPointParameters
 input parameters More...
 
std::vector< std::stringfSystParameterNames
 names of parameters we are floating from the input point More...
 

Detailed Description

Definition at line 36 of file FNEXCovarianceMatrixMaker_plugin.cc.

Member Typedef Documentation

template<typename UserConfig , typename KeysToIgnore = void>
using art::ResultsProducer::Table = ProducerTable<UserConfig, detail::PluginConfig, KeysToIgnore>
inherited

Definition at line 114 of file ResultsProducer.h.

Constructor & Destructor Documentation

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

Definition at line 77 of file FNEXCovarianceMatrixMaker_plugin.cc.

References reconfigure().

78  : fRand(TRandom3(0))
79  {
80  this->reconfigure(pset);
81 
82  return;
83  }
TRandom3 fRand
RNG for picking the variation in parameters.
void reconfigure(fhicl::ParameterSet const &pset)
fnex::CovarianceMatrixMaker::~CovarianceMatrixMaker ( )
virtual

Definition at line 86 of file FNEXCovarianceMatrixMaker_plugin.cc.

87  {
88  }
fnex::CovarianceMatrixMaker::CovarianceMatrixMaker ( CovarianceMatrixMaker const &  )
delete
fnex::CovarianceMatrixMaker::CovarianceMatrixMaker ( CovarianceMatrixMaker &&  )
delete

Member Function Documentation

void fnex::CovarianceMatrixMaker::beginJob ( )
overridevirtual

Reimplemented from art::ResultsProducer.

Definition at line 132 of file FNEXCovarianceMatrixMaker_plugin.cc.

References b, fnex::cBeamType_Strings, fnex::cSelectionType_Strings, d, e, fBinUtil, fCovarianceMatrix, fEventLists, fInputPointParameters, fManipulatorParameters, fNominalEnergySpectra, fNominalSpectrum, fRand, fShiftedSpectrum, fShifts, fSystParameterNames, fTFS, novadaq::cnv::DetInfo::GetName(), fnex::kBeam, fnex::kCosmicBackgroundFile, findDuplicateFiles::key, fnex::kFileTypeStrings, fnex::kNuESelectionLowPID, fnex::kNuESelectionMidPID, fnex::kNuESelectionPeripheral, fnex::kNuMuSelectionQ1, fnex::kNuMuSelectionQ4, fnex::kSwap, fnex::kTauSwap, LOG_DEBUG, m, art::TFileDirectory::make(), string, and plotROC::title.

133  {
134  // Create histograms for the covariance matrix, the nominal spectrum and
135  // the shifted values
136  // Each axis accounts for both detectors, both beam types and all desired selections
137  // Don't break out the interaction types or file types because they aren't known in
138  // the data
139  // The ND has 4 numu spectra and 2 nue
140  // The FD has 4 numu spectra and 2 nue and 1 peripheral
141  // For each beam type I need 8 * fBinUtil->NuMuHighEdges().size(),
142  // 4 * fBinUtil->NuEHighEdges.size() + 1
143  int numBins = 2 * (4 * fBinUtil->NuEHighEdges().size() +
144  8 * fBinUtil->NuMuHighEdges().size() +
145  1);
146  fCovarianceMatrix = fTFS->make<TH2D>("CovarianceMatrix",
147  ";Energy Bin;Energy Bin",
148  numBins,
149  1,
150  numBins + 1,
151  numBins,
152  1,
153  numBins + 1);
154 
155  fNominalSpectrum = fTFS->make<TH1D>("NominalBin",
156  ";Energy Bin;Events",
157  numBins,
158  1,
159  numBins + 1);
160 
161  fShiftedSpectrum = fTFS->make<TH1D>("ShiftedBin",
162  ";Energy Bin;Events",
163  numBins,
164  1,
165  numBins + 1);
166 
167 
168  std::stringstream titles;
169  titles << "Seed: "
170  << fRand.GetSeed()
171  << ";Shifts;Iterations";
172  for(auto name : fSystParameterNames){
173  fShifts[name] = fTFS->make<TH1D>((name+"Shifts").c_str(),
174  titles.str().c_str(),
175  500,
176  -5.,
177  5);
178  }
179 
180 
181  // make histograms for the actual energy spectrum too
182  // first have to determine the boundaries
183  int key = 0;
184  int bdf = 0;
185  double maxe = 0.;
188  std::set<fnex::FileType_t> fileTypes({fnex::kBeam,
189  fnex::kSwap,
192 
193  // loop over beams
194  for(int b = 0; b < 2; ++b){
195  // have to have the same bins in the ND and FD
196  for(int d = 0; d < 2; ++d){
197 
198  // loop over file types - the ND only cares about
199  // the nonswap files, FD has nonswap, fluxswap and tauswap
200  for(auto fitr : fileTypes){
201 
202  // in the ND, we only care about the nonswap file type
203  if(d == 0 && fitr != fnex::kBeam) continue;
204 
205  bdf = (b + 1) * 1000 + (d + 1) * 100 + (fitr + 1) * 10;
206 
208 
209  // MidPID selection is not used after 2017
210  // We only have peripheral samples in the FD
212  (e == fnex::kNuESelectionPeripheral && d == 0)) continue;
213 
214  key = bdf + e;
215 
216  maxe = (e == fnex::kNuESelectionPeripheral) ? 10. : fBinUtil->NuEHighEdges().rbegin()->first;
217  name = (fnex::cBeamType_Strings[b] +
219  fnex::kFileTypeStrings[fitr] +
221 
222  title = ";Energy (GeV);Events/10^{20} POT";
223 
224  fNominalEnergySpectra[key] = fTFS->make<TH1D>(name.c_str(), title.c_str(),
225  fBinUtil->NuEHighEdges().size() + 1,
226  0,
227  maxe);
228  } // end loop over nue selections
229 
230  // now the numu bins
231  for(size_t m = fnex::kNuMuSelectionQ1; m < fnex::kNuMuSelectionQ4 + 1; ++m){
232 
233  key = bdf + m;
234 
235  name = (fnex::cBeamType_Strings[b] +
237  fnex::kFileTypeStrings[fitr] +
239 
240  title = (d < 1) ? ";Energy (GeV);10^{3} Events/10^{20} POT" : ";Energy (GeV);Events/10^{20} POT";
241 
242  fNominalEnergySpectra[key] = fTFS->make<TH1D>(name.c_str(), title.c_str(),
243  fBinUtil->NuMuHighEdges().size() + 1,
244  0,
245  fBinUtil->NuMuHighEdges().rbegin()->first);
246  } // end loop over numu selections
247 
248  } // end loop over file types
249  } // end loop over detectors
250  } // end loop over beam types
251 
252  LOG_DEBUG("CovarianceMatrixMaker")
253  << "histograms made";
254 
255  // get the lists of events from the TTree and put them into a map
256  // of event lists
257  std::unique_ptr<fnex::EventListManipulator> manipulator = std::make_unique<fnex::EventListManipulator>(fManipulatorParameters,
259 
260  // we only want the MC lists
261  fEventLists = manipulator->DeserializeMC();
262 
263  return;
264  }
static std::string GetName(int id)
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< int, TH1D * > fNominalEnergySpectra
Nominal energy spectrum for each detector/file/beam/selection.
const XML_Char * name
Definition: expat.h:151
fnex::EventListMap fEventLists
the lists of events we are going to use, data and MC
std::map< std::string, TH1D * > fShifts
Shifts selected for each parameter adjusted.
TRandom3 fRand
RNG for picking the variation in parameters.
std::vector< std::string > fSystParameterNames
names of parameters we are floating from the input point
std::unique_ptr< fnex::CovarianceBinUtility > fBinUtil
useful functions for mapping bins to energy and back
art::ServiceHandle< art::TFileService > fTFS
TFileService.
const std::string kFileTypeStrings[8]
Definition: Constants.h:386
Float_t d
Definition: plot.C:236
const std::string cBeamType_Strings[4]
Definition: Constants.h:76
TH1D * fShiftedSpectrum
Shifted spectrum for each detector/beam/selection.
T * make(ARGS...args) const
fhicl::ParameterSet fInputPointParameters
input parameters
const hit & b
Definition: hits.cxx:21
fhicl::ParameterSet fManipulatorParameters
the fake point parameters
const std::string cSelectionType_Strings[11]
Definition: Constants.h:101
Float_t e
Definition: plot.C:35
TH1D * fNominalSpectrum
Nominal spectrum for each detector/beam/selection.
enum BeamMode string
void fnex::CovarianceMatrixMaker::clear ( )
overridevirtual

Implements art::ResultsProducer.

Definition at line 123 of file FNEXCovarianceMatrixMaker_plugin.cc.

References fEventLists.

124  {
125  fEventLists.clear();
126 
127  return;
128  }
fnex::EventListMap fEventLists
the lists of events we are going to use, data and MC
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
void art::ResultsProducer::doBeginJob ( )
inlineinherited

Definition at line 165 of file ResultsProducer.h.

References ana::assert(), breakpoints::beginJob(), fhicl::ParameterSetRegistry::get(), and art::Consumer::setModuleDescription().

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

166 {
168  // Preparing the consumer for the job must be done after the
169  // constructer has been called.
170  auto const& mainID = moduleDescription_->mainParameterSetID();
171  auto const& scheduler_pset =
173  "services.scheduler");
175  prepareForJob(scheduler_pset);
176  beginJob();
177 }
static collection_type const & get() noexcept
void setModuleDescription(ModuleDescription const &md)
void prepareForJob(fhicl::ParameterSet const &pset)
assert(nhit_max >=nhit_nbins)
virtual void beginJob()
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doBeginRun ( RunPrincipal const &  rp)
inlineinherited

Definition at line 201 of file ResultsProducer.h.

References r().

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

202 {
203  Run const r{rp, *moduleDescription_, this};
204  beginRun(r);
205 }
virtual void beginRun(Run const &)
TRandom3 r(0)
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doBeginSubRun ( SubRunPrincipal const &  srp)
inlineinherited

Definition at line 187 of file ResultsProducer.h.

References sr.

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

188 {
189  SubRun const sr{srp, *moduleDescription_, this};
190  beginSubRun(sr);
191 }
virtual void beginSubRun(SubRun const &)
caf::StandardRecord * sr
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doClear ( )
inlineinherited

Definition at line 229 of file ResultsProducer.h.

References clear.

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

230 {
231  clear();
232 }
virtual void clear()=0
void art::ResultsProducer::doEndJob ( )
inlineinherited

Definition at line 180 of file ResultsProducer.h.

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

181 {
182  endJob();
184 }
virtual void endJob()
void showMissingConsumes() const
void art::ResultsProducer::doEndRun ( RunPrincipal const &  rp)
inlineinherited

Definition at line 208 of file ResultsProducer.h.

References r().

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

209 {
210  Run const r{rp, *moduleDescription_, this};
211  endRun(r);
212 }
virtual void endRun(Run const &)
TRandom3 r(0)
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doEndSubRun ( SubRunPrincipal const &  srp)
inlineinherited

Definition at line 194 of file ResultsProducer.h.

References sr.

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

195 {
196  SubRun const sr{srp, *moduleDescription_, this};
197  endSubRun(sr);
198 }
caf::StandardRecord * sr
virtual void endSubRun(SubRun const &)
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doEvent ( EventPrincipal const &  ep)
inlineinherited

Definition at line 215 of file ResultsProducer.h.

References e, and lem_server::ep.

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

216 {
217  Event const e{ep, *moduleDescription_, this};
218  event(e);
219 }
Float_t e
Definition: plot.C:35
virtual void event(Event const &)
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doReadResults ( ResultsPrincipal const &  resp)
inlineinherited

Definition at line 222 of file ResultsProducer.h.

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

223 {
224  Results const res{resp, *moduleDescription_, this};
225  readResults(res);
226 }
virtual void readResults(Results const &)
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::ResultsProducer::doWriteResults ( ResultsPrincipal )
inherited
void fnex::CovarianceMatrixMaker::FillSpectrum ( TH1D *  spectrumBin,
std::map< int, TH1D * > &  spectraEnergy 
)
private

Definition at line 283 of file FNEXCovarianceMatrixMaker_plugin.cc.

References bin, e, energy, evt, fBinUtil, fEventLists, Fill(), fnex::ShifterAndWeighter::Instance(), findDuplicateFiles::key, novadaq::cnv::kNEARDET, fnex::kNu_RecoE, fnex::kSystAndOscWgt, LOG_DEBUG, fetch_tb_beamline_files::md, PandAna.reco_validation.add_data::offset, ana::weight, and fnex::ShifterAndWeighter::Weight().

Referenced by readResults(), and writeResults().

285  {
286  // first reset the spectra
287  spectrumBin ->Reset();
288  for(auto hitr : spectraEnergy)
289  hitr.second->Reset();
290 
291  // declare some variables we will be using a lot in the for loops below
292  double weight = 1.;
293  double energy = 0.;
294  int key = 0;
295  int bin = 0;
296  int offset = 0;
297  double normalization = 1.;
298  double potForNorm = 1.e8; // spill summary POT values are in units of 10^12 POT,
299  // so this normalization would be to 10^20 POT
300 
301  // loop over each list and event in the list
302  for(auto itr : fEventLists){
303  auto const md = itr.first;
304 
305  normalization = potForNorm/itr.second.ListSpillSummary().goodPOT;
306 
307  // normalize the numu selected ND down to a reasonable number of events
308  // to have about the same peak as the highest fd bins. In the end we
309  // are just looking to see relative changes in each bin anyway.
310  if(md.detector == novadaq::cnv::kNEARDET){
311  if(md.IsNuMuSelected()) normalization *= 1.e-3;
312  else if(md.IsNuESelected() ) normalization *= 1.e-2;
313  }
314 
315  key = fBinUtil->MetaDataToKey(md);
316 
317  // figure out the offsets
318  offset = fBinUtil->KeyToOffset(key);
319 
320  LOG_DEBUG("CovarianceMatrixMaker")
321  << md.ToString()
322  << " key: "
323  << fBinUtil->MetaDataToKey(md)
324  << " bin offset: "
325  << offset;
326 
327  // add the file type to the key for the energy spectra
328  key += (md.fileType + 1) * 10;
329 
330  for(auto const& evt : itr.second){
331 
332  energy = evt->dataVals->val_at(fnex::kNu_RecoE, md);
333  bin = fBinUtil->EnergyToBin(energy, md);
334 
335  // if bin is negative then the energy is out of range for
336  // the selection type and we'll ignore it.
337  if(bin < 0) continue;
338 
340 
341  // now fill the spectrum
342  spectrumBin->Fill(bin + offset, weight * normalization);
343 
344  if(spectraEnergy.count(key) > 0)
345  spectraEnergy[key]->Fill(energy, weight * normalization);
346 
347  } // end loop over events
348  } // end loop over lists of events
349 
350  return;
351  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
static const unsigned char kNu_RecoE
Definition: VarVals.h:36
const Var weight
fnex::EventListMap fEventLists
the lists of events we are going to use, data and MC
static ShifterAndWeighter * Instance()
std::unique_ptr< fnex::CovarianceBinUtility > fBinUtil
useful functions for mapping bins to energy and back
correl_yv Fill(-(dy[iP-1][iC-1]), hyv->GetBinContent(iP, iC))
double Weight(fnex::EventPtr const &curEvent, fnex::MetaData const &md, fnex::WeightType_t const wgtType=kAllWgt)
int evt
double energy
Definition: plottest35.C:25
Near Detector in the NuMI cavern.
float bin[41]
Definition: plottest35.C:14
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
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
CovarianceMatrixMaker& fnex::CovarianceMatrixMaker::operator= ( CovarianceMatrixMaker const &  )
delete
CovarianceMatrixMaker& fnex::CovarianceMatrixMaker::operator= ( CovarianceMatrixMaker &&  )
delete
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
template<class P >
void art::ResultsProducer::produces ( std::string const &  instanceName = {})
inlineprotectedinherited

Definition at line 159 of file ResultsProducer.h.

160 {
161  ProductRegistryHelper::produces<P, InResults>(instanceName);
162 }
void fnex::CovarianceMatrixMaker::readResults ( art::Results const &  r)
overridevirtual

Reimplemented from art::ResultsProducer.

Definition at line 267 of file FNEXCovarianceMatrixMaker_plugin.cc.

References FillSpectrum(), fNominalEnergySpectra, fNominalSpectrum, and LOG_DEBUG.

268  {
269  // The shifter and weighter was initialized in the EventListManipulator::Deserialize() method
270 
271  // fill the nominal histograms first so we don't do this for every time we
272  // change the systematic parameters
274 
275  LOG_DEBUG("CovarianceMatrixMaker")
276  << "nominal spectrum filled";
277 
278  return;
279  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< int, TH1D * > fNominalEnergySpectra
Nominal energy spectrum for each detector/file/beam/selection.
void FillSpectrum(TH1D *spectrumBin, std::map< int, TH1D * > &spectraEnergy)
TH1D * fNominalSpectrum
Nominal spectrum for each detector/beam/selection.
void fnex::CovarianceMatrixMaker::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 91 of file FNEXCovarianceMatrixMaker_plugin.cc.

References fBinUtil, fInputPointParameters, fIterations, fManipulatorParameters, fRand, fSystParameterNames, fhicl::ParameterSet::get(), fhicl::ParameterSet::get_names(), and string.

Referenced by CovarianceMatrixMaker().

92  {
93  // create the manipulator
94  fManipulatorParameters = pset.get< fhicl::ParameterSet >("EventListManipulator");
95  fIterations = pset.get< int >("Iterations", 1000);
96  fInputPointParameters = pset.get< fhicl::ParameterSet >("InitialGuessInputPoint");
97  auto randSeed = pset.get< unsigned long int >("RandomSeed", 0);
98 
99  if(randSeed > 0) fRand.SetSeed(randSeed);
100 
101  // get data samples to use from the manipulatorParameters
102  fBinUtil = std::make_unique<fnex::CovarianceBinUtility>();
103 
104  auto systematicParameters = fInputPointParameters.get< fhicl::ParameterSet >("SystematicPullInitial");
105  auto parNames = systematicParameters.get_names();
106 
107  fhicl::ParameterSet systPars;
108  for(const auto &name : parNames){
109  systPars = systematicParameters.get<fhicl::ParameterSet>(name);
110 
111  // don't bother with any systematics parameters that have been set to fixed
112  if(systPars.get<bool>("Fixed")) continue;
113 
114  fSystParameterNames.push_back(systPars.get<std::string>("Parameter"));
115  }
116 
117  return;
118  }
const XML_Char * name
Definition: expat.h:151
int fIterations
number of iterations for picking sigmas
TRandom3 fRand
RNG for picking the variation in parameters.
std::vector< std::string > fSystParameterNames
names of parameters we are floating from the input point
std::unique_ptr< fnex::CovarianceBinUtility > fBinUtil
useful functions for mapping bins to energy and back
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< std::string > get_names() const
fhicl::ParameterSet fInputPointParameters
input parameters
fhicl::ParameterSet fManipulatorParameters
the fake point parameters
enum BeamMode string
void art::ResultsProducer::registerProducts ( MasterProductRegistry mpr,
ProductDescriptions producedProducts,
ModuleDescription const &  md 
)
inlineinherited

Definition at line 128 of file ResultsProducer.h.

References fetch_tb_beamline_files::md, and art::ProductRegistryHelper::registerProducts().

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

131  {
132  ProductRegistryHelper::registerProducts(mpr, producedProducts, md);
134  }
void registerProducts(MasterProductRegistry &mpr, ProductDescriptions &productsToRegister, ModuleDescription const &md)
cet::exempt_ptr< ModuleDescription const > moduleDescription_
void art::Consumer::setModuleDescription ( ModuleDescription const &  md)
protectedinherited
void fnex::CovarianceMatrixMaker::SetSystematicParameter ( fnex::InputPoint point)
private

Definition at line 358 of file FNEXCovarianceMatrixMaker_plugin.cc.

References fRand, fShifts, fSystParameterNames, fnex::ShifterAndWeighter::Instance(), novadaq::cnv::kFARDET, novadaq::cnv::kNEARDET, LOG_DEBUG, make_pair(), fnex::ShifterAndWeighter::SetCurrentVals(), and fnex::InputPoint::SystematicPulls().

Referenced by writeResults().

359  {
360 
361  // we will pick a random value from a unit gaussian, ie gaussian with
362  // sigma = 1. That will be the fractional change on the sigma we want
363  // to apply to the new input point
364  double sigFrac = 0.;
365 
366  LOG_DEBUG("CovarianceMatrixMaker")
367  << "sigfrac = "
368  << sigFrac
369  << " original point "
370  << point;
371 
372  ParameterDetMap systematicPulls = point.SystematicPulls();
373 
374  for(auto name : fSystParameterNames) {
377 
378  // each systematic parameter should have a different random number
379  // change in sigma so that we don't artificially make them change
380  // in a correlated way if doing more than one parameter in a job
381  sigFrac = fRand.Gaus();
382 
383  if((name.find("CalibShape") != std::string::npos ||
384  name.find("Cherenkov") != std::string::npos) &&
385  sigFrac < 0.) sigFrac *= -1.;
386 
387  fShifts[name]->Fill(sigFrac);
388 
389  LOG_DEBUG("CovarianceMatrixMaker")
390  << " parameter: "
391  << name
392  << " sigFrac "
393  << sigFrac;
394 
395  if(systematicPulls.count(tempPairFar) != 0){
396  systematicPulls[tempPairFar] = sigFrac;
397 
398  LOG_DEBUG("CovarianceMatrixMaker")
399  << "FD name: "
400  << name
401  << " "
402  << systematicPulls[tempPairFar];
403  }
404  if(systematicPulls.count(tempPairNear) != 0){
405  systematicPulls[tempPairNear] = sigFrac;
406 
407  LOG_DEBUG("CovarianceMatrixMaker")
408  << "ND name: "
409  << name
410  << " "
411  << systematicPulls[tempPairFar];
412  }
413  } // end loop over systematic parameters to change
414 
415  // Make the new input point
416  //
417  point = fnex::InputPoint(point.ParameterSpaceLocation(),
418  systematicPulls,
419  point.FixedParameters(),
420  point.FixedSystematics() );
421 
422  LOG_DEBUG("CovarianceMatrixMaker")
423  << " new point "
424  << point;
425 
427 
428  return;
429  }
void SetCurrentVals(fnex::InputPoint const &curPoint)
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const XML_Char * name
Definition: expat.h:151
std::map< std::string, TH1D * > fShifts
Shifts selected for each parameter adjusted.
TRandom3 fRand
RNG for picking the variation in parameters.
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
std::vector< std::string > fSystParameterNames
names of parameters we are floating from the input point
static ShifterAndWeighter * Instance()
Far Detector at Ash River, MN.
Near Detector in the NuMI cavern.
std::unordered_map< ParameterDet, double, ParameterDetHasher > ParameterDetMap
Definition: Constants.h:63
std::pair< std::string, novadaq::cnv::DetId > ParameterDet
Definition: Constants.h:38
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

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

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited
void fnex::CovarianceMatrixMaker::writeResults ( art::Results r)
overridevirtual

Implements art::ResultsProducer.

Definition at line 432 of file FNEXCovarianceMatrixMaker_plugin.cc.

References std::abs(), DEFINE_ART_RESULTS_PLUGIN, fCovarianceMatrix, FillSpectrum(), fInputPointParameters, fIterations, fNominalSpectrum, fShiftedEnergySpectra, fShiftedSpectrum, MECModelEnuComparisons::i, std::isnan(), calib::j, LOG_VERBATIM, nbins, cet::pow(), and SetSystematicParameter().

433  {
434  // declare some variables we will be using a lot in the for loops below
435  int nbins = fNominalSpectrum->GetNbinsX();
436  double diffI = 0.;
437  double diffJ = 0.;
438  double iCenter = 0.;
439 
441 
442  // loop over all the events and fill the matrices for many different
443  // values of the systematic parameters
444  for(int k = 0; k < fIterations; ++k){
445 
446  LOG_VERBATIM("CovarianceMatrixMaker")
447  << "iteration: "
448  << k;
449 
450  this->SetSystematicParameter(point);
451 
452  // this is a new shift for the parameter, so reset and refill the spectrum
454 
455  // now to fill the covariance matrices
456  // For ROOT histograms bin 0 is the underflow bin, so start at bin 1
457  // if either diffI or diffJ are 0, then we don't need to fill
458  // the bin with a 0 (ie the product) and can continue on
459  for(int i = 1; i < nbins + 1; ++i){
460  iCenter = fNominalSpectrum->GetBinCenter(i);
461  diffI = (fShiftedSpectrum->GetBinContent(i) - fNominalSpectrum->GetBinContent(i));
462  if(diffI != 0.) diffI /= fNominalSpectrum->GetBinContent(i);
463  else continue;
464 
465  for(int j = 1; j < nbins + 1; ++j){
466  diffJ = (fShiftedSpectrum->GetBinContent(j) - fNominalSpectrum->GetBinContent(j));
467  if (diffJ != 0.) diffJ /= fNominalSpectrum->GetBinContent(j);
468  else continue;
469  /*
470  if(i == 1)
471  LOG_VERBATIM("CovarianceMatrixMaker")
472  << "i: "
473  << i
474  << " shifted i: "
475  << fShiftedSpectrum->GetBinContent(i)
476  << " nominal i: "
477  << fNominalSpectrum->GetBinContent(i)
478  << " j: "
479  << j
480  << " shifted j: "
481  << fShiftedSpectrum->GetBinContent(j)
482  << " nominal j: "
483  << fNominalSpectrum->GetBinContent(j)
484  << " diffI: "
485  << diffI
486  << " diffJ: "
487  << diffJ
488  << " product: "
489  << diffI * diffJ;
490  */
491  fCovarianceMatrix->Fill(iCenter, fNominalSpectrum->GetBinCenter(j), diffI * diffJ);
492  } // end loop over j bins of spectrum
493  } // end loop over i bins of spectrum
494 
495  } // end loop over the iterations on the systematic parameter
496 
497  // protect against very low and very high covariances
498  // these usually happen because nentries in these bins for nominal
499  // and shifted spectra are identially 0
500  for (int i = 1; i < nbins + 1; ++i){
501  for (int j = 1; j < fCovarianceMatrix->GetNbinsY()+1; j++){
502  double binContent = fCovarianceMatrix->GetBinContent(i,j);
503  if (std::abs(binContent) < std::pow(10,-14) || std::abs(binContent) > std::pow(10,14) || isnan(binContent)) {
504  // LOG_VERBATIM("CovarianceMatrixMaker")
505  // << "bin " << i
506  // << ", covariance: " << binContent
507  // << "\n -- nominal i: " << fNominalSpectrum->GetBinContent(i)
508  // << "\n -- shifted i: " << fShiftedSpectrum->GetBinContent(i)
509  // << "\n -- nominal minus shifted i: " << fNominalSpectrum->GetBinContent(i) - fShiftedSpectrum->GetBinContent(i)
510  // << "\n -- nominal j: " << fNominalSpectrum->GetBinContent(j)
511  // << "\n -- shifted j: " << fShiftedSpectrum->GetBinContent(j)
512  // << "\n -- nominal minus shifted j: " << fNominalSpectrum->GetBinContent(j) - fShiftedSpectrum->GetBinContent(j)
513  // << "\n -- diffI*diffJ" << (fNominalSpectrum->GetBinContent(i)-fShiftedSpectrum->GetBinContent(i))*(fNominalSpectrum->GetBinContent(j)-fShiftedSpectrum->GetBinContent(j));
514 
515  fCovarianceMatrix->SetBinContent(i,j,0);
516  fCovarianceMatrix->SetBinContent(j,i,0);
517  }
518  }
519  }
520 
521  return;
522  }
int fIterations
number of iterations for picking sigmas
constexpr T pow(T x)
Definition: pow.h:75
std::map< int, TH1D * > fShiftedEnergySpectra
Shifted energy spectrum for each detector/file/beam/selection.
float abs(float number)
Definition: d0nt_math.hpp:39
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
const int nbins
Definition: cellShifts.C:15
void SetSystematicParameter(fnex::InputPoint &point)
const double j
Definition: BetheBloch.cxx:29
TH1D * fShiftedSpectrum
Shifted spectrum for each detector/beam/selection.
fhicl::ParameterSet fInputPointParameters
input parameters
void FillSpectrum(TH1D *spectrumBin, std::map< int, TH1D * > &spectraEnergy)
#define LOG_VERBATIM(category)
TH1D * fNominalSpectrum
Nominal spectrum for each detector/beam/selection.

Member Data Documentation

std::unique_ptr<fnex::CovarianceBinUtility> fnex::CovarianceMatrixMaker::fBinUtil
private

useful functions for mapping bins to energy and back

Definition at line 60 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), FillSpectrum(), and reconfigure().

TH2D* fnex::CovarianceMatrixMaker::fCovarianceMatrix
private

Covariance matrix.

Definition at line 66 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), and writeResults().

fnex::EventListMap fnex::CovarianceMatrixMaker::fEventLists
private

the lists of events we are going to use, data and MC

Definition at line 65 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), clear(), and FillSpectrum().

fhicl::ParameterSet fnex::CovarianceMatrixMaker::fInputPointParameters
private

input parameters

Definition at line 72 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), reconfigure(), and writeResults().

int fnex::CovarianceMatrixMaker::fIterations
private

number of iterations for picking sigmas

Definition at line 62 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by reconfigure(), and writeResults().

fhicl::ParameterSet fnex::CovarianceMatrixMaker::fManipulatorParameters
private

the fake point parameters

Definition at line 64 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), and reconfigure().

std::map<int, TH1D*> fnex::CovarianceMatrixMaker::fNominalEnergySpectra
private

Nominal energy spectrum for each detector/file/beam/selection.

Definition at line 68 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), and readResults().

TH1D* fnex::CovarianceMatrixMaker::fNominalSpectrum
private

Nominal spectrum for each detector/beam/selection.

Definition at line 67 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), readResults(), and writeResults().

TRandom3 fnex::CovarianceMatrixMaker::fRand
private

RNG for picking the variation in parameters.

Definition at line 63 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), reconfigure(), and SetSystematicParameter().

std::map<int, TH1D*> fnex::CovarianceMatrixMaker::fShiftedEnergySpectra
private

Shifted energy spectrum for each detector/file/beam/selection.

Definition at line 70 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by writeResults().

TH1D* fnex::CovarianceMatrixMaker::fShiftedSpectrum
private

Shifted spectrum for each detector/beam/selection.

Definition at line 69 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), and writeResults().

std::map<std::string, TH1D*> fnex::CovarianceMatrixMaker::fShifts
private

Shifts selected for each parameter adjusted.

Definition at line 71 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), and SetSystematicParameter().

std::vector<std::string> fnex::CovarianceMatrixMaker::fSystParameterNames
private

names of parameters we are floating from the input point

Definition at line 73 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob(), reconfigure(), and SetSystematicParameter().

art::ServiceHandle<art::TFileService> fnex::CovarianceMatrixMaker::fTFS
private

TFileService.

Definition at line 61 of file FNEXCovarianceMatrixMaker_plugin.cc.

Referenced by beginJob().


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