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

Public Types

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

Public Member Functions

 CMFDecorrelator (fhicl::ParameterSet const &p)
 
 CMFDecorrelator (CMFDecorrelator const &)=delete
 
 CMFDecorrelator (CMFDecorrelator &&)=delete
 
CMFDecorrelatoroperator= (CMFDecorrelator const &)=delete
 
CMFDecorrelatoroperator= (CMFDecorrelator &&)=delete
 
void clear () override
 
void writeResults (art::Results &res) override
 
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

int CantorPairingFunction (int k1, int k2)
 
void SetComponentNameAndOffsets ()
 
void SetTemplateMatrix ()
 
void FillHistogramFromMatrix (Eigen::MatrixXd matrix, TH1D *hist)
 
void FillHistogramFromVector (std::vector< float > spectrum, TH1D *hist)
 
void FillFractionalHistograms (TH1D *ps, TH1D *init, TH1D *decor)
 
void DecorrelateAgainstComponent (Eigen::MatrixXd matrix, int nComponentBins, int componentOffset)
 
void AddEpsilonToDiagonal (Eigen::MatrixXd &matrix)
 
Eigen::MatrixXd CycleMatrixComponents (Eigen::MatrixXd thisMat)
 

Private Attributes

art::ServiceHandle< art::TFileServicefTFS
 TFileService. More...
 
fhicl::ParameterSet fManipulatorParameters
 event list manipulator parameters More...
 
fhicl::ParameterSet fSAWParameters
 shifter and weighter parameters More...
 
bool fSystPlusStat
 include stats in decorrelation More...
 
cmf::Location loc
 parameter location More...
 
TH2D * matrixHist = nullptr
 
TH1D * initialError = nullptr
 
TH1D * decorrelatedError = nullptr
 
TH1D * predictedSpectra = nullptr
 
TH1D * initialFractionalError = nullptr
 
TH1D * decorrelatedFractionalError = nullptr
 
Eigen::MatrixXd covarianceMatrix
 
Eigen::MatrixXd templateMatrix
 
Eigen::MatrixXd decorrelatedMatrix
 
Eigen::MatrixXd E_11
 
Eigen::MatrixXd E_21
 
Eigen::MatrixXd E_12
 
Eigen::MatrixXd E_22
 
Eigen::MatrixXd E_bar
 
std::map< int, intcomponentInformation
 
std::vector< cmf::SubMatrixDatathisSubMatrixDataVec
 

Detailed Description

Definition at line 39 of file CMFDecorrelator_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

cmf::CMFDecorrelator::CMFDecorrelator ( fhicl::ParameterSet const &  p)
explicit

Definition at line 106 of file CMFDecorrelator_plugin.cc.

References decorrelatedError, decorrelatedFractionalError, fManipulatorParameters, fSAWParameters, fSystPlusStat, fTFS, fhicl::ParameterSet::get(), initialError, initialFractionalError, TMVAGlob::Initialize(), cmf::ShifterAndWeighter::InitShiftsAndWeightsToUse(), cmf::CovarianceBinUtility::Instance(), cmf::ParameterUtility::Instance(), cmf::ChiSqrCalculator::Instance(), cmf::SelectionUtility::Instance(), cmf::ShifterAndWeighter::Instance(), loc, art::TFileDirectory::make(), matrixHist, nbins, cmf::ParameterUtility::ParametersAsLocation(), predictedSpectra, and cmf::CovarianceBinUtility::TotalBins().

109 {
110 
111  fManipulatorParameters = p.get< fhicl::ParameterSet >("EventListManipulator" );
112  fSAWParameters = p.get< fhicl::ParameterSet >("ShifterAndWeighterConfig");
113  fSystPlusStat = p.get< bool >("SystPlusStat", false );
114 
115  cmf::SelectionUtility::Instance() -> Initialize(p.get<fhicl::ParameterSet>("SelectionsToUse"));
117  cmf::ParameterUtility::Instance() -> Initialize(p.get<fhicl::ParameterSet>("ParametersToUse"));
118  cmf::ChiSqrCalculator::Instance() -> InitializeCovarianceMatrix(p.get<fhicl::ParameterSet>("ChiSqrCalculationParameters"));
119 
121 
123  fSAWParameters);
124 
125 
126  // this just pulls nbins for the configured selections
128 
129  matrixHist = fTFS->make<TH2D>("CovarianceMatrix",
130  ";Logical Bin;Logical Bin",
131  nbins, 0, nbins,
132  nbins, 0, nbins);
133 
134  predictedSpectra = fTFS->make<TH1D>("PredictedSpectra",
135  ";Logical Bin;Predicted Events",
136  nbins, 0, nbins);
137 
138  initialError = fTFS->make<TH1D>("InitialError",
139  ";Logical Bin;Total Uncertainty",
140  nbins, 0, nbins);
141 
142  decorrelatedError = fTFS->make<TH1D>("DecorrelatedError",
143  ";Logical Bin;Total Uncertainty",
144  nbins, 0, nbins);
145 
146  initialFractionalError = fTFS->make<TH1D>("InitialFractionalError",
147  ";Logical Bin; Fractional Uncertainty",
148  nbins, 0, nbins);
149 
150  decorrelatedFractionalError = fTFS->make<TH1D>("DecorrelatedFractionalError",
151  ";Logical Bin; Fractional Uncertainty",
152  nbins, 0, nbins);
153 
154 
155 }
fhicl::ParameterSet fManipulatorParameters
event list manipulator parameters
const char * p
Definition: xmltok.h:285
static SelectionUtility * Instance()
cmf::Location loc
parameter location
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.C:184
art::ServiceHandle< art::TFileService > fTFS
TFileService.
static ParameterUtility * Instance()
const int nbins
Definition: cellShifts.C:15
T get(std::string const &key) const
Definition: ParameterSet.h:231
fhicl::ParameterSet fSAWParameters
shifter and weighter parameters
bool fSystPlusStat
include stats in decorrelation
static ShifterAndWeighter * Instance()
static cmf::ChiSqrCalculator * Instance()
size_t TotalBins(bool allSels=false)
void InitShiftsAndWeightsToUse(cmf::Location const &loc, fhicl::ParameterSet const &parset)
T * make(ARGS...args) const
cmf::Location ParametersAsLocation()
static CovarianceBinUtility * Instance()
cmf::CMFDecorrelator::CMFDecorrelator ( CMFDecorrelator const &  )
delete
cmf::CMFDecorrelator::CMFDecorrelator ( CMFDecorrelator &&  )
delete

Member Function Documentation

void cmf::CMFDecorrelator::AddEpsilonToDiagonal ( Eigen::MatrixXd &  matrix)
private

Definition at line 221 of file CMFDecorrelator_plugin.cc.

References MECModelEnuComparisons::i.

Referenced by writeResults().

221  {
222  for (int i = 0; i < thisMat.cols(); ++i){
223  thisMat(i,i) += 0.001;
224  }
225 }
int cmf::CMFDecorrelator::CantorPairingFunction ( int  k1,
int  k2 
)
private

Definition at line 164 of file CMFDecorrelator_plugin.cc.

Referenced by SetTemplateMatrix().

164  {
165  return (((k1 + k2) * (k1 + k2 + 1))/2) + k2;
166 }
void cmf::CMFDecorrelator::clear ( )
overridevirtual

Implements art::ResultsProducer.

Definition at line 158 of file CMFDecorrelator_plugin.cc.

159 {
160  // Implementation of required member function here.
161 }
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
Eigen::MatrixXd cmf::CMFDecorrelator::CycleMatrixComponents ( Eigen::MatrixXd  thisMat)
private

Definition at line 228 of file CMFDecorrelator_plugin.cc.

References MECModelEnuComparisons::i, calib::j, and thisSubMatrixDataVec.

Referenced by writeResults().

228  {
229 
230  int matrixSize = thisMat.cols();
231 
232  Eigen::MatrixXd templateMatrixCycled(matrixSize,matrixSize);
233  cmf::SubMatrixData testSubMatrixData;
234 
235  // move c_last,last to c_0,0
236  templateMatrixCycled(0,0) = thisMat(matrixSize-1,matrixSize-1);
237 
238  // correct the 0th row
239  for (int i = 1; i < thisMat.cols(); i++){
240  for (size_t iv = 0; iv < thisSubMatrixDataVec.size(); iv++){
241  if (thisSubMatrixDataVec.at(iv).CantorPairingNumber == thisMat(matrixSize-1, i-1))
242  testSubMatrixData = thisSubMatrixDataVec.at(iv);
243  }
244  templateMatrixCycled(0,i) = thisMat(matrixSize-1,i-1);
245  }
246 
247  // correct the 1th column
248  for (int i = 1; i < thisMat.cols(); i++){
249  for (size_t iv = 0; iv < thisSubMatrixDataVec.size(); iv++){
250  if (thisSubMatrixDataVec.at(iv).CantorPairingNumber == thisMat(i-1, matrixSize-1))
251  testSubMatrixData = thisSubMatrixDataVec.at(iv);
252  }
253  templateMatrixCycled(i,0) = thisMat(i-1, matrixSize-1);
254  }
255 
256  // and now the rest
257  for (int i = 1; i < templateMatrixCycled.rows(); i++){
258  for (int j = 1; j < templateMatrixCycled.cols(); j++){
259 
260  for (size_t iv = 0; iv < thisSubMatrixDataVec.size(); iv++){
261  if (thisSubMatrixDataVec.at(iv).CantorPairingNumber == thisMat(i-1, j-1))
262  testSubMatrixData = thisSubMatrixDataVec.at(iv);
263  }
264 
265  templateMatrixCycled(i,j) = thisMat(i-1,j-1);
266  }
267 
268  }
269  return templateMatrixCycled;
270 }
std::vector< cmf::SubMatrixData > thisSubMatrixDataVec
const double j
Definition: BetheBloch.cxx:29
void cmf::CMFDecorrelator::DecorrelateAgainstComponent ( Eigen::MatrixXd  matrix,
int  nComponentBins,
int  componentOffset 
)
private

Definition at line 301 of file CMFDecorrelator_plugin.cc.

References decorrelatedMatrix, E_11, E_12, E_21, E_22, E_bar, MECModelEnuComparisons::i, and LOG_DEBUG.

Referenced by writeResults().

303  {
304 // now decorrelate each bin not in the 0,0 sample
305 
306  int binIterator = 1;
307  for (int i = 0; i < nComponentBins; i++){
308 
309  // firstly, size submatrices to be correct size
310  // and get the submatrices.
311 
312  int totCovMatNCols = matrix.cols()-1;
313 
314  E_11.resize(1 , 1 );
315  E_21.resize(totCovMatNCols , 1 );
316  E_12.resize(1 , totCovMatNCols );
317  E_22.resize(totCovMatNCols , totCovMatNCols );
318 
319  E_11 = matrix.topLeftCorner (1 , 1 ) ;
320  E_12 = matrix.topRightCorner (1 , totCovMatNCols ) ;
321  E_21 = matrix.bottomLeftCorner (totCovMatNCols , 1 ) ;
322  E_22 = matrix.bottomRightCorner(totCovMatNCols , totCovMatNCols ) ;
323 
324  E_bar = E_11 - (E_12 * (E_22.inverse() * E_21));
325 
326  LOG_DEBUG("tmp")
327  << "E_11(" << E_11.rows() << "," << E_11.cols() << ") "
328  << "E_21(" << E_21.rows() << "," << E_21.cols() << ") "
329  << "E_12(" << E_12.rows() << "," << E_12.cols() << ") "
330  << "E_22(" << E_22.rows() << "," << E_22.cols() << ") "
331  << "E_bar(" << E_bar.rows() << "," << E_bar.cols() << ")";
332 
333  decorrelatedMatrix(i+componentOffset,i+componentOffset) = E_bar(0,0);
334 
335  matrix = E_22;
336 
337  binIterator++;
338 
339  }
340 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
Eigen::MatrixXd decorrelatedMatrix
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 cmf::CMFDecorrelator::FillFractionalHistograms ( TH1D *  ps,
TH1D *  init,
TH1D *  decor 
)
private

Definition at line 287 of file CMFDecorrelator_plugin.cc.

References decorrelatedFractionalError, MECModelEnuComparisons::i, and initialFractionalError.

Referenced by writeResults().

289  {
290 
291  // for whatever reason, art doesn't like it when you clone TH1s, so now do
292  // this dumb thing
293 
294  for (int i = 0; i < initialFractionalError->GetNbinsX(); ++i){
295  initialFractionalError->SetBinContent(i+1, init->GetBinContent(i+1)/ps->GetBinContent(i+1));
296  decorrelatedFractionalError->SetBinContent(i+1, decor->GetBinContent(i+1)/ps->GetBinContent(i+1));
297  }
298 }
void cmf::CMFDecorrelator::FillHistogramFromMatrix ( Eigen::MatrixXd  matrix,
TH1D *  hist 
)
private

Definition at line 273 of file CMFDecorrelator_plugin.cc.

References MECModelEnuComparisons::i, confusionMatrixTree::matrix, and std::sqrt().

Referenced by writeResults().

273  {
274  for (int i = 0; i < h->GetNbinsX(); ++i){
275  h->SetBinContent(i+1, std::sqrt(matrix(i,i)));
276  }
277 }
T sqrt(T number)
Definition: d0nt_math.hpp:156
void cmf::CMFDecorrelator::FillHistogramFromVector ( std::vector< float >  spectrum,
TH1D *  hist 
)
private

Definition at line 280 of file CMFDecorrelator_plugin.cc.

References MECModelEnuComparisons::i.

Referenced by writeResults().

280  {
281  for (size_t i = 0; i < s.size(); ++i){
282  h->SetBinContent(i+1, s[i]);
283  }
284 }
const XML_Char * s
Definition: expat.h:262
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
CMFDecorrelator& cmf::CMFDecorrelator::operator= ( CMFDecorrelator const &  )
delete
CMFDecorrelator& cmf::CMFDecorrelator::operator= ( CMFDecorrelator &&  )
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 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 cmf::CMFDecorrelator::SetComponentNameAndOffsets ( )
private

Definition at line 170 of file CMFDecorrelator_plugin.cc.

References componentInformation, cmf::CovarianceBinUtility::Instance(), cmf::SelectionUtility::Instance(), findDuplicateFiles::key, and cmf::CovarianceBinUtility::KeyToOffset().

Referenced by writeResults().

170  {
171  for (auto const& dbsItr : cmf::SelectionUtility::Instance()->SelectionsToUse()){
172  for (auto const& key : dbsItr.Keys()) componentInformation[key] = cmf::CovarianceBinUtility::Instance()->KeyToOffset(key);
173  }
174 }
int KeyToOffset(long const &key, bool allSels=false)
static SelectionUtility * Instance()
std::map< int, int > componentInformation
static CovarianceBinUtility * Instance()
void art::Consumer::setModuleDescription ( ModuleDescription const &  md)
protectedinherited
void cmf::CMFDecorrelator::SetTemplateMatrix ( )
private

Definition at line 177 of file CMFDecorrelator_plugin.cc.

References CantorPairingFunction(), componentInformation, MECModelEnuComparisons::i, cmf::CovarianceBinUtility::Instance(), makeTrainCVSamples::int, calib::j, LOG_DEBUG, cmf::CovarianceBinUtility::SelectionHighEdges(), templateMatrix, and thisSubMatrixDataVec.

Referenced by writeResults().

177  {
178 
179  int nComponents = componentInformation.size();
180  templateMatrix.resize(nComponents, nComponents);
181 
182  int i = 0;
183  for(const auto& it_i : componentInformation){
184 
185  int j = 0;
186  for(const auto& it_j : componentInformation){
187 
189 
190  LOG_DEBUG("CMFDecorrelator")
191  << "\n cpn : " << templateMatrix(i,j)
192  << "\n key i : " << it_i.first
193  << "\n off i : " << it_i.second
194  << "\n pos i : " << i
195  << "\n nbin i: " << (int)cmf::CovarianceBinUtility::Instance()->SelectionHighEdges(it_i.first).size()
196  << "\n key j :" << it_j.first
197  << "\n off j :" << it_j.second
198  << "\n pos j :" << j
199  << "\n nbin j:" << (int)cmf::CovarianceBinUtility::Instance()->SelectionHighEdges(it_j.first).size();
200 
201  SubMatrixData thisSubMatrixData(templateMatrix(i,j),
202  it_i.first,
203  it_i.second,
204  i,
205  (int)cmf::CovarianceBinUtility::Instance()->SelectionHighEdges(it_i.first).size(),
206  it_j.first,
207  it_j.second,
208  j,
210 
211  thisSubMatrixDataVec.push_back(thisSubMatrixData);
212 
213  j++;
214  }
215  i++;
216  }
217 
218 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::vector< cmf::SubMatrixData > thisSubMatrixDataVec
const double j
Definition: BetheBloch.cxx:29
int CantorPairingFunction(int k1, int k2)
std::map< double, int > const & SelectionHighEdges(cmf::MetaData const &md)
std::map< int, int > componentInformation
static CovarianceBinUtility * Instance()
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

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

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited
void cmf::CMFDecorrelator::writeResults ( art::Results res)
overridevirtual

Implements art::ResultsProducer.

Definition at line 343 of file CMFDecorrelator_plugin.cc.

References AddEpsilonToDiagonal(), plot_validation_datamc::c, componentInformation, cmf::SubMatrixData::ComponentKeyI, cmf::SubMatrixData::ComponentKeyJ, confusionMatrixTree::count, covarianceMatrix, CycleMatrixComponents(), DecorrelateAgainstComponent(), decorrelatedError, decorrelatedMatrix, DEFINE_ART_RESULTS_PLUGIN, cmf::EventListManipulator::Deserialize(), cmf::EventListManipulator::ExposureMap(), cmf::ChiSqrCalculator::FillCovarianceMatrix(), FillFractionalHistograms(), FillHistogramFromMatrix(), FillHistogramFromVector(), cmf::FillSpectrum(), fManipulatorParameters, fSystPlusStat, initialError, cmf::ChiSqrCalculator::Instance(), cmf::kMC, LOG_VERBATIM, matrixHist, cmf::SubMatrixData::NumBinsI, cmf::SubMatrixData::NumBinsJ, cmf::SubMatrixData::OffsetI, cmf::SubMatrixData::OffsetJ, predictedSpectra, r(), SetComponentNameAndOffsets(), cmf::ChiSqrCalculator::SetSpectrum(), SetTemplateMatrix(), templateMatrix, thisSubMatrixDataVec, and Zero().

344 {
345 
346  // we're pulling in the elm so we can on-the-fly change the prediction
347  // by getting the correct "full" matrix for the fractional matrix
348 
350 
351  cmf::EventListColl eventLists;
352  manipulator.Deserialize(eventLists, cmf::kMC);
353 
354  cmf::ExposureMap exposureMap = manipulator.ExposureMap();
355 
356  std::vector<float> spectrum;
357  std::vector<float> count;
358 
359  cmf::FillSpectrum(eventLists,
360  exposureMap,
361  spectrum,
362  count);
363 
364  cmf::ChiSqrCalculator::Instance()->SetSpectrum(spectrum, false);
365 
366  // make a matrix for the calculation
367  covarianceMatrix = Eigen::MatrixXd::Zero(spectrum.size(), spectrum.size());
368  decorrelatedMatrix = Eigen::MatrixXd::Zero(spectrum.size(), spectrum.size());
369 
370  // get the covariance matrix for only the selections we care about,
371  // and using the predicted spectra from above
372 
375 
376  // fill the histogram to the file
377  for(int r = 0; r < matrixHist->GetNbinsX(); ++r){
378  for(int c = 0; c < matrixHist->GetNbinsX(); ++c){
379  matrixHist->SetBinContent(r+1, c+1, covarianceMatrix(r,c));
380  }
381  }
382 
383  // the decorrelation "rotates" the covariance matrix so that each iteration
384  // a different component takes the 0,0 place in order to decorrelate
385  // each component against each other component.
386  //
387  // the easiest way to do that is with a template matrix
388 
390  this->SetTemplateMatrix();
391 
392  for (size_t iComponent = 0; iComponent < componentInformation.size(); ++iComponent){
393 
394  Eigen::MatrixXd oldMat(spectrum.size(), spectrum.size());
395  Eigen::MatrixXd newMat(spectrum.size(), spectrum.size());
396 
397  // figure out the number of bins for this 0,0 component
398  int nComponentBins = 0;
399  int componentOffset = 0;
400  for ( size_t iv = 0; iv < thisSubMatrixDataVec.size(); ++iv ){
401  if (thisSubMatrixDataVec.at(iv).CantorPairingNumber == templateMatrix(0,0)){
402  nComponentBins = thisSubMatrixDataVec.at(iv).NumBinsI;
403  componentOffset = thisSubMatrixDataVec.at(iv).OffsetI;
404  }
405  }
406 
407  // construct oldMat using information from the templateMatrix
408  SubMatrixData thisSubMatrixData;
409  int offseti = 0;
410  for (int itmplt = 0; itmplt < templateMatrix.rows(); itmplt++){
411 
412  int offsetj = 0;
413  for (int jtmplt = 0; jtmplt < templateMatrix.cols(); jtmplt++){
414 
415  // find the corresponding SubMatrixData
416  for (size_t k = 0; k < thisSubMatrixDataVec.size(); k++){
417  if (thisSubMatrixDataVec.at(k).CantorPairingNumber == templateMatrix(itmplt,jtmplt))
418  thisSubMatrixData = thisSubMatrixDataVec.at(k);
419  }
420 
421  LOG_VERBATIM("CovarianceMatrixDecorrelator")
422  << "Found component "
423  << thisSubMatrixData.ComponentKeyI
424  << ", "
425  << thisSubMatrixData.ComponentKeyJ
426  << " --- "
427  << nComponentBins
428  << " bins";
429 
430  // now loop over the relevant bins in the
431  // covariance matrix and fill in the oldMat with the correct bins
432  int iom = 0;
433  int finalBinI = thisSubMatrixData.OffsetI + thisSubMatrixData.NumBinsI;
434  int finalBinJ = thisSubMatrixData.OffsetJ + thisSubMatrixData.NumBinsJ;
435  for (int izrm = thisSubMatrixData.OffsetI; izrm < finalBinI; izrm++){
436  int jom = 0;
437  for (int jzrm = thisSubMatrixData.OffsetJ; jzrm < finalBinJ; jzrm++){
438  oldMat(offseti+iom,offsetj+jom) = covarianceMatrix(izrm, jzrm);
439  jom++;
440  }
441  iom++;
442  }
443  offsetj += thisSubMatrixData.NumBinsJ;
444  }
445  offseti+= thisSubMatrixData.NumBinsI;
446  }
447 
448  newMat = oldMat;
449 
450  this->DecorrelateAgainstComponent(newMat, nComponentBins, componentOffset);
452  }
453 
454  // fill histograms
455  this->FillHistogramFromVector(spectrum, predictedSpectra);
456  this->FillHistogramFromMatrix(decorrelatedMatrix, decorrelatedError);
459 }
std::map< cmf::MetaData, cmf::SpillSummary > ExposureMap
Definition: Structs.h:215
Eigen::MatrixXd decorrelatedMatrix
void AddEpsilonToDiagonal(Eigen::MatrixXd &matrix)
fhicl::ParameterSet fManipulatorParameters
event list manipulator parameters
void FillHistogramFromMatrix(Eigen::MatrixXd matrix, TH1D *hist)
void DecorrelateAgainstComponent(Eigen::MatrixXd matrix, int nComponentBins, int componentOffset)
Eigen::MatrixXd CycleMatrixComponents(Eigen::MatrixXd thisMat)
std::vector< cmf::SubMatrixData > thisSubMatrixDataVec
void FillFractionalHistograms(TH1D *ps, TH1D *init, TH1D *decor)
bool fSystPlusStat
include stats in decorrelation
void FillSpectrum(cmf::EventListColl const &eventLists, cmf::ExposureMap const &exposureMap, std::vector< float > &spectrum, std::vector< float > &count, cmf::InteractionType_t intType, bool applyExposureNorm)
void SetSpectrum(std::vector< float > const &spectrum, bool isData)
void FillHistogramFromVector(std::vector< float > spectrum, TH1D *hist)
static cmf::ChiSqrCalculator * Instance()
std::vector< cmf::EventList > EventListColl
Definition: Event.h:147
void Zero()
Eigen::MatrixXd covarianceMatrix
TRandom3 r(0)
#define LOG_VERBATIM(category)
std::map< int, int > componentInformation
void FillCovarianceMatrix(Eigen::MatrixXd &matrix, bool isSystOnly=false)

Member Data Documentation

std::map<int, int> cmf::CMFDecorrelator::componentInformation
private
Eigen::MatrixXd cmf::CMFDecorrelator::covarianceMatrix
private

Definition at line 91 of file CMFDecorrelator_plugin.cc.

Referenced by writeResults().

TH1D* cmf::CMFDecorrelator::decorrelatedError = nullptr
private

Definition at line 86 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and writeResults().

TH1D* cmf::CMFDecorrelator::decorrelatedFractionalError = nullptr
private

Definition at line 89 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and FillFractionalHistograms().

Eigen::MatrixXd cmf::CMFDecorrelator::decorrelatedMatrix
private

Definition at line 93 of file CMFDecorrelator_plugin.cc.

Referenced by DecorrelateAgainstComponent(), and writeResults().

Eigen::MatrixXd cmf::CMFDecorrelator::E_11
private

Definition at line 94 of file CMFDecorrelator_plugin.cc.

Referenced by DecorrelateAgainstComponent().

Eigen::MatrixXd cmf::CMFDecorrelator::E_12
private

Definition at line 96 of file CMFDecorrelator_plugin.cc.

Referenced by DecorrelateAgainstComponent().

Eigen::MatrixXd cmf::CMFDecorrelator::E_21
private

Definition at line 95 of file CMFDecorrelator_plugin.cc.

Referenced by DecorrelateAgainstComponent().

Eigen::MatrixXd cmf::CMFDecorrelator::E_22
private

Definition at line 97 of file CMFDecorrelator_plugin.cc.

Referenced by DecorrelateAgainstComponent().

Eigen::MatrixXd cmf::CMFDecorrelator::E_bar
private

Definition at line 98 of file CMFDecorrelator_plugin.cc.

Referenced by DecorrelateAgainstComponent().

fhicl::ParameterSet cmf::CMFDecorrelator::fManipulatorParameters
private

event list manipulator parameters

Definition at line 79 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and writeResults().

fhicl::ParameterSet cmf::CMFDecorrelator::fSAWParameters
private

shifter and weighter parameters

Definition at line 80 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator().

bool cmf::CMFDecorrelator::fSystPlusStat
private

include stats in decorrelation

Definition at line 81 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and writeResults().

art::ServiceHandle<art::TFileService> cmf::CMFDecorrelator::fTFS
private

TFileService.

Definition at line 77 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator().

TH1D* cmf::CMFDecorrelator::initialError = nullptr
private

Definition at line 85 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and writeResults().

TH1D* cmf::CMFDecorrelator::initialFractionalError = nullptr
private

Definition at line 88 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and FillFractionalHistograms().

cmf::Location cmf::CMFDecorrelator::loc
private

parameter location

Definition at line 82 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator().

TH2D* cmf::CMFDecorrelator::matrixHist = nullptr
private

Definition at line 84 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and writeResults().

TH1D* cmf::CMFDecorrelator::predictedSpectra = nullptr
private

Definition at line 87 of file CMFDecorrelator_plugin.cc.

Referenced by CMFDecorrelator(), and writeResults().

Eigen::MatrixXd cmf::CMFDecorrelator::templateMatrix
private

Definition at line 92 of file CMFDecorrelator_plugin.cc.

Referenced by SetTemplateMatrix(), and writeResults().

std::vector< cmf::SubMatrixData > cmf::CMFDecorrelator::thisSubMatrixDataVec
private

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