NuFCRunInfo Class Reference

#include <NuFCRunInfo.h>

List of all members.

Public Member Functions

 NuFCRunInfo (NuMMRun *run, const TString &name="")
void SetRun (NuMMRun *run)
NuMMRunGetRun (void)
const NuMMRunGetRun (void) const
void AddFile (const TString &fle)
TString GetName (void) const
 Get the name of this Run.
const NuFCEventManagerEvents (void) const
 Retrieve the event manager.
void BuildSummaries (void)
 Build the event summary histograms.
void BuildSampleWeights (const NuMMParameters &TrueParams)
 Build the sample weight histograms.
NuMatrixSpectrum GetSummary (const NuFCSample &sample) const
NuMatrixSpectrum GetNoRWSummary (const NuFCSample &sample) const
const NuMatrixGetNDSummary (void) const
 Retrieves the (weighted) near detector summary.
const NuMatrixSpectrumGetSampleWeight (const NuFCSample &sample) const
const NuMatrixSpectrumGetTruePrediction (const NuFCSample &sample) const
 Retrieves the true energy prediction histogram for a sample.
const NuMatrixGetBlankFD (void) const
 Returns a blank FD spectrum that can be used as a basis for other things.
Bool_t Validate (void)

Static Public Member Functions

static NuFCRunInfoBuildMMRunFC (TString name, TString helper, Double_t POT)
static NuFCRunInfoBuildFromConfig (ConfigFile &config, const TString &section)

Private Member Functions

 NuFCRunInfo (const NuFCRunInfo &)
 Copying is disallowed - NuMMRun has no copy semantics.
const NuFCRunInfooperator= (const NuFCRunInfo &)
void BuildFDSummaries (void)
 Build the FD event summary histograms.
void BuildNDSummary (void)
 Build the ND event summary histograms.

Private Attributes

NuMMRunfRunObject
 The completely generic run object.
std::vector< TString > fEventFiles
 A list of input event files.
TString fName
 A name for the Run - to distinguish with errors.
NuFCEventManager fEvents
 The event library object for this run.
std::map< NuFCSample,
NuMatrixSpectrum
fEventSummaries
 A list of event manager true-energy summaries.
std::map< NuFCSample,
NuMatrixSpectrum
fEventSummariesNoRW
std::auto_ptr< NuMatrixfNDEventSummary
 A Summary of the ND events (reco energy, unshifted, and weighted).
std::map< NuFCSample,
NuMatrixSpectrum
fEventSampleWeights
 A list of sample correction histograms.
std::map< NuFCSample,
NuMatrixSpectrum
fFDPredictions
std::auto_ptr< NuMatrixfBlankFD
 An internal copy of the format of the FD.

Detailed Description

Contains the information about a single run. This object should contain all of the information required to apply the feldman-cousins procedure to a single analysis-type and/or run period. Each is unique and cannot be duplicated - this is because the MMRun object does not have copying semantics.

Definition at line 24 of file NuFCRunInfo.h.


Constructor & Destructor Documentation

NuFCRunInfo::NuFCRunInfo ( const NuFCRunInfo  )  [private]

Copying is disallowed - NuMMRun has no copy semantics.

Definition at line 60 of file NuFCRunInfo.cxx.

Referenced by BuildMMRunFC().

00061 {
00062   // Don't allow us to ever copy this class
00063   assert(0);
00064 }

NuFCRunInfo::NuFCRunInfo ( NuMMRun run,
const TString &  name = "" 
)

Initialise the Run information class.

Parameters:
run Must be a valid extrapolator object, that is never deleted.
name Is an optional name for this (without spaces)

Definition at line 36 of file NuFCRunInfo.cxx.

References fBlankFD, fName, get_unused_name(), NuMMRun::GetFDData(), Msg::kWarning, MSG, and NuMMRun::QuietModeOn().

00037   : fRunObject(run), fName(name)
00038 {
00039   assert(run);
00040   
00041   // Set the run to quiet mode
00042   run->QuietModeOn();
00043   
00044   fBlankFD = run->GetFDData();
00045   if (!fBlankFD->Complete()) {
00046     MSG("NuFCRunInfo",Msg::kWarning)
00047       << "Attempt at retrieval of blank FD Spectrum failed because histogram is incomplete"
00048       << endl;
00049   }
00050   fBlankFD->Multiply(0);
00051   
00052   if (name.IsNull()) {
00053     // Have some fallback for unassigned names
00054     fName = get_unused_name();
00055   }
00056 }


Member Function Documentation

void NuFCRunInfo::AddFile ( const TString &  fle  ) 

Add a file to the input file list.

Definition at line 76 of file NuFCRunInfo.cxx.

References NuFCEventManager::AddFile(), fEventFiles, and fEvents.

00077 {
00078   fEventFiles.push_back(file);
00079   
00080   // Add this file to our event manager
00081   fEvents.AddFile(file);
00082 }

void NuFCRunInfo::BuildFDSummaries ( void   )  [private]

Build the FD event summary histograms.

Definition at line 143 of file NuFCRunInfo.cxx.

References base, NuFCEventManager::FDEvents(), fEvents, fEventSummaries, fEventSummariesNoRW, NuMatrix1D::Fill(), fNDEventSummary, fRunObject, NuMatrix::GetFillTypeEnergy(), GetRun(), Msg::kError, MSG, NuEventVector< T >::pot(), NuMMRun::ResetNDData(), NuMatrix::ResetPOT(), NuFCEventManager::Samples(), NuMatrix1D::Scale(), NuMatrix::SetFillTrueEnergy(), and NuMMRun::TrueComponents().

Referenced by BuildSummaries().

00144 {
00145   // Make sure we already generated the ND summary
00146   if (!fNDEventSummary.get()) {
00147     MSG("NuFCRunInfo",Msg::kError) << "Calling FD summary generation without existing ND summary" << endl;
00148     throw runtime_error("Calling FD summary generation without existing ND summary");
00149   }
00150   
00151   // Get rid of all of the old summaries
00152   fEventSummaries.clear();
00153   fEventSummariesNoRW.clear();
00154   
00155   // Set the run object to use our ND data summary
00156   GetRun().ResetNDData(*fNDEventSummary);
00157   
00158   // Loop over all samples
00159   vector<NuFCSample>::const_iterator sample;
00160   for (sample = fEvents.Samples().begin(); sample != fEvents.Samples().end(); ++sample)
00161   {
00162     // Get the 'True components' for this sample - to use as a base template
00163     NuMMParameters pars;
00164     NuMatrixSpectrum base = fRunObject->TrueComponents(pars, *sample);
00165     base.Scale(0);
00166     base.SetFillTrueEnergy();
00167     NuMatrixSpectrum baseNoRW = base;
00168     assert(baseNoRW.GetFillTypeEnergy() == base.GetFillTypeEnergy());
00169     
00170     // Now, loop over all events in this sample and add them to the base histogram!
00171     NuEvent nu;
00172     const NuEventVector<NuFCEvent2> &evts = fEvents.FDEvents(*sample);
00173     base.ResetPOT(evts.pot());
00174     cout << "Sample " << (*sample).GetName() << " pot is " << evts.pot() << endl;
00175     NuEventVector<NuFCEvent2>::const_iterator evt;
00176     for (evt = evts.begin(); evt != evts.end(); ++evt)
00177     {
00178       (*evt).Expand(nu);
00179       base.Fill(nu);
00180       // Reset the rw to be identically one - this will be multiplied in later
00181       nu.rw = 1.0;
00182       baseNoRW.Fill(nu);
00183     }
00184     // Fill our map with this spectrum
00185     fEventSummaries[*sample] = base;
00186     fEventSummariesNoRW[*sample] = baseNoRW;
00187     
00188   } // samples
00189 }

NuFCRunInfo * NuFCRunInfo::BuildFromConfig ( ConfigFile config,
const TString &  section 
) [static]

Build a run information object from a section of a configuration file

Definition at line 346 of file NuFCRunInfo.cxx.

References BuildMMRunFC(), Plot::Format(), get_unused_name(), ConfigFile::GetFloat(), ConfigFile::GetInt(), ConfigFile::GetString(), Msg::kError, and MSG.

00347 {
00348   // Convert the TString to a string
00349   string section = sectionTS.Data();
00350   
00351   TString name = cfg.GetString("Name", section, "");
00352   Double_t POT = cfg.GetFloat("POT", section, 0.0);
00353   TString extrapolator = cfg.GetString("Extrapolator", section);
00354 
00355   // Handle the case where the name is unspecified
00356   if (name.IsNull()) name = get_unused_name();
00357 
00358   // Validate the values
00359   assert(POT != 0.0);
00360   assert(!extrapolator.IsNull());
00361   
00362   // Blank pointer to create
00363   NuFCRunInfo *ri = 0;
00364   // Build the run according to the provided extrapolator
00365   if (extrapolator == "NuMMRunFC") {
00366     TString helper = cfg.GetString("Helper", section, "");
00367     assert(!helper.IsNull());
00368     //BuildMMRunFC(TString name, TString helperstr, Double_t POT)
00369     ri = NuFCRunInfo::BuildMMRunFC(name, helper, POT);
00370   } else {
00371     MSG("NuFCRunInfo",Msg::kError) << "Error: Do not know how to create extrapolator " << extrapolator << endl;
00372     throw runtime_error("Did not recognise extrapolator type in configuration generator");
00373   }
00374 
00375   // Now read the event files
00376   Int_t num_event_files = cfg.GetInt("event_files", section, 0);
00377   assert(num_event_files != 0);
00378   for (Int_t fileindex = 0; fileindex < num_event_files; ++fileindex) {
00379     TString key = TString::Format("event_file_%d", fileindex);
00380     TString filename = cfg.GetString(key.Data(), section);
00381     if (filename.IsNull()) {
00382       MSG("NuFCRunInfo",Msg::kError) << "Event files listed but not specified in configuration!" << endl;
00383       throw runtime_error("Event files listed but not specified in configuration!");
00384     }
00385     ri->AddFile(filename);
00386   }
00387   
00388   return ri;
00389 }

NuFCRunInfo * NuFCRunInfo::BuildMMRunFC ( TString  name,
TString  helper,
Double_t  POT 
) [static]

Build a runinfo object preconfigured to use a NuMMRunFC extrapolator. You will still need to add the event library files to this, but this should help cut down on the maintenance code. This returns a pointer that the user has to delete themselves - this is not ideal, but this class has no copy semantics, and additionally this routine is specifically designed to be used from the script-end of things i.e. CINT is awful and can't deal with auto_ptrs very well.

Definition at line 313 of file NuFCRunInfo.cxx.

References NuMMHelperCPT::FDNuPurity(), NuGeneral::GetReleaseDirToUse(), NuFCRunInfo(), NuMMRunNuBar::SetHelperOwnership(), and NuMMRun::SetMaximumEnergy().

Referenced by BuildFromConfig().

00314 {
00315   // Work out the Xsec file to use then build the helper
00316   NuGeneral gen;
00317   const string releaseDir = gen.GetReleaseDirToUse("NtupleUtils");
00318   const string xsec = releaseDir+"/NtupleUtils/data/xsec_minos_modbyrs4_v3_5_0_mk.root";
00319   NuMMHelperCPT *helper = new NuMMHelperCPT(helperstr,TString(xsec.c_str()));
00320   
00321   // Grab a 'fake' empty ND histogram out of this.
00322   // The ND will be regenerated from event libraries so we don't need a real histogram
00323   assert(helper->FDNuPurity());
00324   TH1D hBlank(*reinterpret_cast<const TH1D*>(helper->FDNuPurity()));
00325   hBlank.SetNameTitle("herror", "Blank default ND data: Something went wrong");
00326   NuMatrixSpectrum tmpND(hBlank, 1.0);
00327   
00328   
00329   // Build the Extrapolator
00330   NuMMRunFC *mmrun = new NuMMRunFC(helper, &tmpND, &tmpND, POT);
00331   // Tell the run to delete the helper on destruction
00332   mmrun->SetHelperOwnership(true);
00333   
00334   // Constrain the maximum fitting energy of this run
00335   mmrun->SetMaximumEnergy(49.99999);
00336     
00337   NuFCRunInfo *runInfo = new NuFCRunInfo(mmrun, name);
00338   
00339   // Now, build and return the run object
00340   return runInfo;
00341 }

void NuFCRunInfo::BuildNDSummary ( void   )  [private]

Build the ND event summary histograms.

Definition at line 107 of file NuFCRunInfo.cxx.

References Events(), fNDEventSummary, NuMMRun::GetNDData(), GetRun(), it, NuFCEventManager::NDEvents(), NuEventVector< T >::pot(), and NuMMRun::ResetNDData().

Referenced by BuildSummaries().

00108 {
00109   // Get a copy of the run's histogram to use as a base
00110   fNDEventSummary = GetRun().GetNDData();
00111   assert(fNDEventSummary.get());
00112   
00113   // Wipe it and set filling method
00114   fNDEventSummary->SetFillRecoEnergy();
00115   fNDEventSummary->Scale(0);
00116   
00117   // Now, get the list of events in the run
00118   const NuEventVector<NuFCEvent2> &events = Events().NDEvents();
00119   
00120   // Set the new ND POT (this should not change, but do it here anwyay)
00121   fNDEventSummary->ResetPOT(events.pot());
00122   
00123   // Copy these events into the new ND spectrum
00124   NuEvent nu;
00125   NuEventVector<NuFCEvent2>::const_iterator it;
00126   for (it = events.begin(); it != events.end(); ++it)
00127   {
00128     (*it).Expand(nu);
00129     
00130     // Each experiment should be systematically shifted here
00131     // NuSystematic syst;
00132     // syst.SetShiftsAsValues(shifts);
00133     // sys.Shift(fNu);
00134     
00135     fNDEventSummary->Fill(nu);
00136   }
00137   // Set the run's ND object to this
00138   GetRun().ResetNDData(*fNDEventSummary);
00139 }

void NuFCRunInfo::BuildSampleWeights ( const NuMMParameters TrueParams  ) 

Build the sample weight histograms.

This 0.87 is a *magic number*. It sets the amount under 1 that events are weighted by - since systematic shifts can increase the event weight, this number can not go over one otherwise it means the probability for an event to be rejected can drop to zero

Definition at line 193 of file NuFCRunInfo.cxx.

References NuMatrixSpectrum::Divide(), MuELoss::e, fEvents, fEventSampleWeights, fFDPredictions, fNDEventSummary, GetNoRWSummary(), NuMatrix::GetPOT(), GetRun(), NuMatrixSpectrum::Multiply(), NuMMRun::ResetNDData(), NuFCEventManager::Samples(), NuMatrixSpectrum::ScaleToPot(), NuMatrixSpectrum::Spectrum(), and NuMMRun::TrueComponents().

00194 {
00195   fEventSampleWeights.clear();
00196   fFDPredictions.clear();
00197   
00198   // Loop over all samples
00199   vector<NuFCSample>::const_iterator sample;
00200   for (sample = fEvents.Samples().begin(); sample != fEvents.Samples().end(); ++sample)
00201   {
00202     // Get a prediction for this sample
00203     // Reset the ND data of our internal run
00204     GetRun().ResetNDData(*fNDEventSummary);
00205     // Get the extrapolated prediction for this sample from the run
00206     NuMatrixSpectrum prediction = GetRun().TrueComponents(TrueParams, *sample);
00207     fFDPredictions[*sample] = prediction;
00208     
00209     // Get the summary for these
00210     NuMatrixSpectrum sampleSummary = GetNoRWSummary(*sample);
00211     // Scale the histogram to the same POT as the extrapolation
00212     // This step isn't stricly necessary as we will scale the weighting histogram
00213     // but it helps with debugging output
00214     sampleSummary.ScaleToPot(prediction.GetPOT());
00215     
00216     // Make and scale the weighting histogram
00217     NuMatrixSpectrum weights = prediction;
00218     weights.Divide(sampleSummary);
00219     Double_t weightMax = weights.Spectrum()->GetMaximum();
00220     // Protect against the case where the prediction is empty
00221     if (weightMax < 1e-15) weightMax = 1.0;
00226     Double_t weightScale = 0.87 / weightMax;
00227     weights.Multiply(weightScale);
00228     
00229     // Assign this weighting histogram to storage
00230     fEventSampleWeights[*sample] = weights;
00231   }
00232 }

void NuFCRunInfo::BuildSummaries ( void   ) 

Build the event summary histograms.

Definition at line 97 of file NuFCRunInfo.cxx.

References BuildFDSummaries(), and BuildNDSummary().

Referenced by TestExperimentGenerator::testAccessSummary(), and TestExperimentGenerator::testBuildSummaries().

00098 {
00099   // Build the ND summary first because we need the ND summary for FD
00100   // template generation
00101   BuildNDSummary();
00102   BuildFDSummaries();
00103 }

const NuFCEventManager& NuFCRunInfo::Events ( void   )  const [inline]
const NuMatrix* NuFCRunInfo::GetBlankFD ( void   )  const [inline]

Returns a blank FD spectrum that can be used as a basis for other things.

Definition at line 107 of file NuFCRunInfo.h.

References fBlankFD.

Referenced by NuFCExperimentGenerator::GenerateFD(), and NuFCExperimentGenerator::GenerateFDSample().

00107 { return fBlankFD.get(); }

TString NuFCRunInfo::GetName ( void   )  const [inline]
const NuMatrix& NuFCRunInfo::GetNDSummary ( void   )  const [inline]

Retrieves the (weighted) near detector summary.

Definition at line 94 of file NuFCRunInfo.h.

References fNDEventSummary.

00094 { return *(fNDEventSummary.get()); };

NuMatrixSpectrum NuFCRunInfo::GetNoRWSummary ( const NuFCSample sample  )  const

Definition at line 254 of file NuFCRunInfo.cxx.

References fEventSummariesNoRW, Msg::kInfo, MSG, and Munits::second.

Referenced by BuildSampleWeights(), and TestExperimentGenerator::testAccessSummary().

00255 {
00256   if (fEventSummariesNoRW.begin() == fEventSummariesNoRW.end()) {
00257     MSG("NuFCRunInfo",Msg::kInfo)
00258       << "No NoRW sample summaries in RunInfo. Have you called BuildSummaries()?" << endl;
00259   }
00260   
00261   if (fEventSummariesNoRW.find(sample) == fEventSummariesNoRW.end()) {
00262     throw runtime_error("Trying to access summary for a sample with no NoRW summary in NuFCRunInfo!");
00263     return NuMatrixSpectrum();
00264   }
00265   
00266   // Return the summary histogram. Use find, because map is const
00267   return (*fEventSummariesNoRW.find(sample)).second;
00268 }

const NuMMRun& NuFCRunInfo::GetRun ( void   )  const [inline]

Definition at line 72 of file NuFCRunInfo.h.

References fRunObject.

00072 { return *fRunObject; }

NuMMRun& NuFCRunInfo::GetRun ( void   )  [inline]
const NuMatrixSpectrum & NuFCRunInfo::GetSampleWeight ( const NuFCSample sample  )  const

Retrieves the sample weight histogram. This is the histogram to weight the MC events by to make the distribution the same shape as the matrix method prediction (in true energy, at least). This is used for rejection sampling. The histogram returned is in true energy.

Definition at line 272 of file NuFCRunInfo.cxx.

References fEventSampleWeights, Msg::kInfo, MSG, and Munits::second.

Referenced by NuFCExperimentGenerator::GenerateFDSample().

00273 {
00274   if (fEventSampleWeights.begin() == fEventSampleWeights.end()) {
00275     MSG("NuFCRunInfo",Msg::kInfo)
00276       << "No sample weights in RunInfo. Have you called BuildSampleWeights(...)?" << endl;
00277     throw runtime_error("Trying to access weights for a sample with no calculated weights in NuFCRunInfo!");
00278   }
00279   
00280   return (*fEventSampleWeights.find(sample)).second;
00281 }

NuMatrixSpectrum NuFCRunInfo::GetSummary ( const NuFCSample sample  )  const

Definition at line 236 of file NuFCRunInfo.cxx.

References fEventSummaries, Msg::kInfo, MSG, and Munits::second.

Referenced by TestExperimentGenerator::testAccessSummary(), and TestExperimentGenerator::testFailSummaryAccess().

00237 {
00238   if (fEventSummaries.begin() == fEventSummaries.end()) {
00239     MSG("NuFCRunInfo",Msg::kInfo)
00240       << "No sample summaries in RunInfo. Have you called BuildSummaries()?" << endl;
00241   }
00242   
00243   if (fEventSummaries.find(sample) == fEventSummaries.end()) {
00244     throw runtime_error("Trying to access summary for a sample with no summary in NuFCRunInfo!");
00245     return NuMatrixSpectrum();
00246   }
00247   
00248   // Return the summary histogram. Use find, because map is const
00249   return (*fEventSummaries.find(sample)).second;
00250 }

const NuMatrixSpectrum & NuFCRunInfo::GetTruePrediction ( const NuFCSample sample  )  const

Retrieves the true energy prediction histogram for a sample.

Definition at line 285 of file NuFCRunInfo.cxx.

References fFDPredictions, Msg::kInfo, MSG, and Munits::second.

Referenced by NuFCExperimentGenerator::GenerateFDSample().

00286 {
00287   if (fFDPredictions.begin() == fFDPredictions.end()) {
00288     MSG("NuFCRunInfo",Msg::kInfo)
00289       << "No predictions in RunInfo. Have you called BuildSampleWeights(...)?" << endl;
00290     throw runtime_error("Trying to predictions for a sample with no calculated weights in NuFCRunInfo!");
00291   }
00292   
00293   return (*fFDPredictions.find(sample)).second;
00294 }

const NuFCRunInfo & NuFCRunInfo::operator= ( const NuFCRunInfo  )  [private]

Definition at line 68 of file NuFCRunInfo.cxx.

00069 {
00070   // Don't ever allow copying
00071   assert(0);
00072 }

void NuFCRunInfo::SetRun ( NuMMRun run  ) 

Set the runtype object. This will transfer ownership to this description class.

Definition at line 298 of file NuFCRunInfo.cxx.

References fBlankFD, fRunObject, NuMMRun::GetFDData(), Msg::kWarning, and MSG.

00299 {
00300   fRunObject = run;
00301   
00302   fBlankFD = run->GetFDData();
00303   if (!fBlankFD->Complete()) {
00304     MSG("NuFCRunInfo",Msg::kWarning)
00305       << "Attempt at retrieval of blank FD Spectrum failed because histogram is incomplete"
00306       << endl;
00307   }
00308   fBlankFD->Multiply(0);
00309 }

Bool_t NuFCRunInfo::Validate ( void   ) 

Validate that we are fully configured for running. This includes having all appropriate events, and a valid run object.

Definition at line 86 of file NuFCRunInfo.cxx.

Referenced by NuFCRunner::push_back().

00087 {
00088   // Check we have Near detector events
00089   // if (fEvents.)
00090   
00091   // For now, always return true!
00092   return true;
00093 }


Member Data Documentation

std::auto_ptr<NuMatrix> NuFCRunInfo::fBlankFD [private]

An internal copy of the format of the FD.

Definition at line 49 of file NuFCRunInfo.h.

Referenced by GetBlankFD(), NuFCRunInfo(), and SetRun().

std::vector<TString> NuFCRunInfo::fEventFiles [private]

A list of input event files.

Definition at line 31 of file NuFCRunInfo.h.

Referenced by AddFile().

The event library object for this run.

Definition at line 37 of file NuFCRunInfo.h.

Referenced by AddFile(), BuildFDSummaries(), BuildSampleWeights(), and Events().

A list of sample correction histograms.

Definition at line 45 of file NuFCRunInfo.h.

Referenced by BuildSampleWeights(), and GetSampleWeight().

A list of event manager true-energy summaries.

Definition at line 40 of file NuFCRunInfo.h.

Referenced by BuildFDSummaries(), and GetSummary().

Definition at line 41 of file NuFCRunInfo.h.

Referenced by BuildFDSummaries(), and GetNoRWSummary().

Definition at line 46 of file NuFCRunInfo.h.

Referenced by BuildSampleWeights(), and GetTruePrediction().

TString NuFCRunInfo::fName [private]

A name for the Run - to distinguish with errors.

Definition at line 34 of file NuFCRunInfo.h.

Referenced by GetName(), and NuFCRunInfo().

std::auto_ptr<NuMatrix> NuFCRunInfo::fNDEventSummary [private]

A Summary of the ND events (reco energy, unshifted, and weighted).

Definition at line 43 of file NuFCRunInfo.h.

Referenced by BuildFDSummaries(), BuildNDSummary(), BuildSampleWeights(), and GetNDSummary().

The completely generic run object.

Definition at line 27 of file NuFCRunInfo.h.

Referenced by BuildFDSummaries(), GetRun(), and SetRun().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1