NuFCExperimentGenerator Class Reference

#include <NuFCExperimentGenerator.h>

List of all members.

Public Member Functions

 NuFCExperimentGenerator (const NuFCRunInfo &run, const NuMMParameters &trueparams)
std::auto_ptr< NuMatrixGenerateND (const NuSystematicShifts &shifts)
 Generate and return a systematically shifted near detector spectrum.
std::auto_ptr< NuMatrixGenerateFD (const NuSystematicShifts &shifts)
 Generate and return a systematically shifted far detector spectrum.
std::auto_ptr< NuMatrixGenerateFDSample (const NuFCSample &sample, const NuSystematicShifts &shifts)
 Generate an individual FD sample.
void SetDelegate (NuFCDelegate *delegate)
 Sets the delegate to use for dumping histogram output.

Private Member Functions

void GotHistogram (TString name, NuMatrix *matrix)

Private Attributes

const NuFCRunInfofRunInfo
 A reference to the runinfo object we are using.
NuEvent fNu
 A blank NuEvent to expand into.
const NuMMParametersfTrueParams
NuFCDelegatefDelegate

Detailed Description

Class to generate experiments

Definition at line 20 of file NuFCExperimentGenerator.h.


Constructor & Destructor Documentation

NuFCExperimentGenerator::NuFCExperimentGenerator ( const NuFCRunInfo run,
const NuMMParameters trueparams 
)

Constructor. Give the RunInfo for the run you want to generate experiments for, and the true parameters to generate on.

Definition at line 25 of file NuFCExperimentGenerator.cxx.

00027   : fRunInfo(run),
00028     fTrueParams(trueparams),
00029     fDelegate(0)
00030 {
00031 
00032 }


Member Function Documentation

std::auto_ptr< NuMatrix > NuFCExperimentGenerator::GenerateFD ( const NuSystematicShifts shifts  ) 

Generate and return a systematically shifted far detector spectrum.

Definition at line 78 of file NuFCExperimentGenerator.cxx.

References NuMatrix::Copy(), NuFCRunInfo::Events(), fRunInfo, GenerateFDSample(), NuFCRunInfo::GetBlankFD(), it, and NuFCEventManager::Samples().

Referenced by NuFCRunner::GenerateExperiment().

00079 {
00080   // For each sample:
00081   //  Poisson Fluctuate
00082   //  Select a random event, shift and rejection sample
00083   // Sum the sample histograms
00084   // Build the Far detector Spectrum
00085   
00086   // Create our end result FD spectrum
00087   auto_ptr<NuMatrix>  fdData(fRunInfo.GetBlankFD()->Copy());
00088   
00089   // Get the vector of samples
00090   vector<NuFCSample> samples = fRunInfo.Events().Samples();
00091   
00092   // For every sample,
00093   vector<NuFCSample>::const_iterator it;
00094   for (it = samples.begin(); it != samples.end(); ++it)
00095   {
00096     NuFCSample smp = *it;
00097     
00098     // Generate the histogram for this sample
00099     auto_ptr<NuMatrix> smpMatrix = GenerateFDSample(smp, shifts);
00100     
00101     fdData->Add(*smpMatrix.get());
00102   }
00103   
00104   return fdData;
00105 }

std::auto_ptr< NuMatrix > NuFCExperimentGenerator::GenerateFDSample ( const NuFCSample sample,
const NuSystematicShifts shifts 
)

Generate an individual FD sample.

Definition at line 109 of file NuFCExperimentGenerator.cxx.

References NuMatrix::Copy(), NuFCEvent2::EnergyMC(), NuFCRunInfo::Events(), NuFCEvent2::Expand(), NuFCEventManager::FDEvents(), fRunInfo, NuFCRunInfo::GetBlankFD(), NuFCRunInfo::GetName(), NuFCRunInfo::GetSampleWeight(), NuFCRunInfo::GetTruePrediction(), GotHistogram(), NuMatrixSpectrum::Integral(), Msg::kWarning, MSG, NuEvent::rw, NuFCEventManager::SampleName(), and NuMatrixSpectrum::Spectrum().

Referenced by GenerateFD().

00110 {
00111   // Generate the prediction and weighting histograms
00112   NuMatrixSpectrum prediction = fRunInfo.GetTruePrediction(sample);
00113   const NuMatrixSpectrum &weights = fRunInfo.GetSampleWeight(sample);
00114   
00115   // Now work out the fluctuated event count
00116   Double_t averageEvents = prediction.Integral();
00117   Int_t poissonEvents = gRandom->Poisson(averageEvents);
00118   // MSG("NuFCExperimentGenerator",Msg::kInfo)
00119   //   << "Prediction for " <<  fRunInfo.Events().SampleName(sample)
00120   //   << " has " << averageEvents << " events. "
00121   //   << "Fluctuated is " << poissonEvents << " events" << endl;
00122   
00123   // Prepare the variables for drawing and filling
00124   const NuEventVector<NuFCEvent2> &evts = fRunInfo.Events().FDEvents(sample);
00125   NuEvent nu;
00126   // Get a new, blank FD spectrum
00127   auto_ptr<NuMatrix>  fdSample(fRunInfo.GetBlankFD()->Copy());
00128   fdSample->SetFillRecoEnergy();
00129   Int_t evtCount = 0, evtDraws = 0;
00130   // Int_t rejectExtrap = 0, rejectRw = 0;
00131   
00132   // Pull out all the events from the distribution
00133   // for (Int_t evtN = 0; evtN < poissonEvents; ++evtN)
00134   // Keep pulling until we get the events we need
00135   while (evtCount < poissonEvents)
00136   {
00137     Double_t rand = gRandom->Uniform();
00138     
00139     // Pick a random event from the sample
00140     Int_t evtIndex = gRandom->Integer(evts.size());
00141     const NuFCEvent2 &evt = evts[evtIndex];
00142     ++evtDraws;
00143     // Get the weight from the truth energy ratio
00144     Int_t bin = weights.Spectrum()->GetXaxis()->FindFixBin(evt.EnergyMC());
00145     Double_t evtWeight = weights.Spectrum()->GetBinContent(bin);
00146   
00147     // Add in the events intrinsic reweight to this
00148     // Is this necessary? In principle, It should not affect the final energy
00149     // spectrum because shape is determined by the rejection sampling..
00150     // What it should do, however, is ensure that the distribution of points within
00151     // a single true energy bin is correct. This might not have any effect, as in
00152     // priciple all events in a single bin should have the same rw value (they don't)
00153     // and this in turn should probably not have any effect on the final answer (as that
00154     // woudl probably indicate some realiance on pt/pz for final reconstructed values, 
00155     // which doesn't make any sense).
00156     // UPDATE:
00157     // This is disabled for now because whilst the rw->reco distributions are independant,
00158     // the shape of the rw distribution in an individual bin compared to another bin can
00159     // affect the probability of rejection for a single bin and therefore change the shape
00160     // of the end distribution by changing a bin-dependent normalisation. The way around
00161     // this is to fluctuate each bin on it's own and control the normalisation that way,
00162     // but that is a bit of a severe change for an effect which we expect to make little,
00163     // if any difference.
00164     // evtWeight *= evt.Rw();
00165   
00166     // Store this pre-systematic weight
00167     // Double_t preSystematicsWeight = evtWeight;
00168   
00169     // TODO: Systematics code
00170     // apply the systematic weight here
00171     // Adjust the event count number if the systematics have affected the event count
00172     
00173     // Warn if we are getting unrejectable probabilities
00174     if (evtWeight > 1.0) {
00175       MSG("NuFCExperimentGenerator",Msg::kWarning)
00176         << "Got rejection probability of " << 1-evtWeight
00177         << "; impossible to reject this event" << endl;
00178     }
00179     // Does this event fail the rejection test?
00180     if (rand > evtWeight) continue;
00181     
00182     // We have passed the event - add to our histogram!
00183     evt.Expand(nu);
00184     nu.rw = 1.0;
00185     fdSample->Fill(nu);
00186     ++evtCount;
00187   }
00188   GotHistogram("FD_"+fRunInfo.GetName()+"_"+fRunInfo.Events().SampleName(sample), fdSample.get());
00189   // MSG("NuFCExperimentGenerator",Msg::kInfo)
00190   //   << "Generated " << poissonEvents << " events" << endl;
00191   // MSG("NuFCExperimentGenerator",Msg::kInfo)
00192   //   << "Drew a total of " << evtDraws << " events." << endl;
00193   
00194   return fdSample;
00195 }

std::auto_ptr< NuMatrix > NuFCExperimentGenerator::GenerateND ( const NuSystematicShifts shifts  ) 

Generate and return a systematically shifted near detector spectrum.

Definition at line 45 of file NuFCExperimentGenerator.cxx.

References NuFCRunInfo::Events(), fNu, fRunInfo, NuMMRun::GetNDData(), NuFCRunInfo::GetRun(), it, NuFCEventManager::NDEvents(), and NuEventVector< T >::pot().

Referenced by NuFCRunner::GenerateExperiment(), and TestExperimentGenerator::testNDGenSingleEvent().

00046 {
00047   // Get a blank copy of the near detector spectrum
00048   assert(fRunInfo.GetRun().GetNDData().get());
00049   auto_ptr<NuMatrix> nd(fRunInfo.GetRun().GetNDData()->Copy());
00050   nd->SetFillRecoEnergy();
00051   nd->Scale(0);
00052   
00053   // Now, get the list of events in the run
00054   const NuEventVector<NuFCEvent2> &events = fRunInfo.Events().NDEvents();
00055   
00056   // Set the new ND POT (this should not change, but do it here anwyay)
00057   nd->ResetPOT(events.pot());
00058   
00059   // Copy these events into the new ND spectrum
00060   NuEventVector<NuFCEvent2>::const_iterator it;
00061   for (it = events.begin(); it != events.end(); ++it)
00062   {
00063     (*it).Expand(fNu);
00064     
00065     // Each experiment should be systematically shifted here
00066     // NuSystematic syst;
00067     // syst.SetShiftsAsValues(shifts);
00068     // sys.Shift(fNu);
00069     
00070     nd->Fill(fNu);
00071   }
00072   return nd;
00073 }

void NuFCExperimentGenerator::GotHistogram ( TString  name,
NuMatrix matrix 
) [private]

Definition at line 36 of file NuFCExperimentGenerator.cxx.

References fDelegate, and NuFCDelegate::GotHistogram().

Referenced by GenerateFDSample().

00037 {
00038   if (!fDelegate) return;
00039   
00040   fDelegate->GotHistogram(name, matrix);
00041 }

void NuFCExperimentGenerator::SetDelegate ( NuFCDelegate delegate  )  [inline]

Sets the delegate to use for dumping histogram output.

Definition at line 58 of file NuFCExperimentGenerator.h.

References fDelegate.

Referenced by NuFCRunner::GenerateExperiment().

00058 { fDelegate = delegate; }


Member Data Documentation

Definition at line 34 of file NuFCExperimentGenerator.h.

Referenced by GotHistogram(), and SetDelegate().

A blank NuEvent to expand into.

Definition at line 26 of file NuFCExperimentGenerator.h.

Referenced by GenerateND().

A reference to the runinfo object we are using.

Definition at line 23 of file NuFCExperimentGenerator.h.

Referenced by GenerateFD(), GenerateFDSample(), and GenerateND().

Definition at line 29 of file NuFCExperimentGenerator.h.


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

Generated on 19 Jun 2017 for loon by  doxygen 1.6.1