Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

NCExtrapolationPID Class Reference

Extrapolation binning events by PID value. More...

#include <NCExtrapolationPID.h>

Inheritance diagram for NCExtrapolationPID:

NCExtrapolation List of all members.

Public Types

typedef std::map< NCBeam::Info,
PIDSpectrum * > 
SpecMap

Public Member Functions

 NCExtrapolationPID (POTMap &dataNear, POTMap &mcNear, POTMap &dataFar, POTMap &mcFar)
virtual ~NCExtrapolationPID ()
virtual void FindSpectraForPars (const NC::OscProb::OscPars *oscPars, const NC::SystPars &systPars, std::vector< NCBeam::Info > beamsToUse, std::vector< TH1 * > &exps, std::vector< TH1 * > &obss)
 Override this in the derived class.

virtual std::vector< const
TH1 * > 
GetNearMCSpectra (std::vector< NCBeam::Info > beamsToUse)
virtual void CleanupSpectra (std::vector< TH1 * > exps, std::vector< TH1 * > obss)
 Called after FindSpectraForPars() to delete necessary spectra.

virtual void AddEvent (NCEventInfo eventInfo, bool useMCAsData, NCType::EFileType fileType, NCBeam::Info beamInfo)
void DoneFilling ()
virtual void WriteResources (const NC::OscProb::OscPars *trueOscPars)
virtual TString GetShortName () const
 This is the name used to name things in the output file etc.

virtual TString GetLongName () const
 This is the name the extrapolation is known under on plots and such.

virtual void Prepare (const Registry &r)
virtual void Reset (bool nearData, bool farData, bool nearMC, bool farMC)
 Causes the extrapolation to forget everything it knows about the requested spectra.

virtual bool EnableNearToFarExtrapolation (bool enable)
 Enable or disable corrections to FD spectra based on ND spectra.


Static Public Member Functions

const RegistryDefaultConfig ()
 Return a default config that will be merged with the NCExtrapolationModule DefaultConfig.


Protected Member Functions

vector< TH1 * > GetExpHists (vector< NCBeam::Info > beamsToUse, const NC::OscProb::OscPars *coords, std::vector< TH1 * > ndSpectra=vector< TH1 * >()) const
 Get the expected histograms in the format required for NCUtils' log likelihood method.

vector< TH1 * > GetObsHists (vector< NCBeam::Info > beamsToUse) const
 Get the observed histograms in the format required for NCUtils' log likelihood method.

vector< TCanvas * > DrawSpectra (const NC::OscProb::OscPars *coords, string suffix="")
 Draw all the spectra.

void WriteSpectra (const NC::OscProb::OscPars *coords, string suffix="")
 Write the spectra, evaluated at the parameters coords, prettily to gDirectory.

void DoneFillingOneBeam (NCBeam::Info beamInfo)
void WriteMCSpectra (const char *filename)
 Save the unoscillated MC spectra to filename so they can be.

void ReadMCSpectra (const char *filename)
 Read the MC spectra from filename, replacing the existing spectra.

double GetMCScaleFactor (const NCBeam::Info &info, Detector::Detector_t det)
 Factor to scale MC by to make it match data.


Protected Attributes

SpecMap spectra
 The 2D spectra, indexed by beam.

bool useCCEnergy
bool useSelectionEnergy
int trueBinFactor
 How much finer to make the true energy binning than the reco.

int nPIDBins
 How many bins in PID to use.

double PIDmin
 The minimum value of PID to use.

double PIDmax
 The maximum value of PID to use.

string mcInFilename
 The filename to read the MC spectra from.

string mcOutFilename
 The filename to write the MC spectra to.

bool doFarNearCorrection
 Whether to do the far/near correction.

bool emulateFarNear
 Whether to emulate the Far/Near method by having just two bins.


Private Member Functions

void PrintMap (POTMap &m, const char *name)
 Print out a POT map for debugging purposes.

void PrintSpectraMap ()

Detailed Description

Extrapolation binning events by PID value.

Definition at line 21 of file NCExtrapolationPID.h.


Member Typedef Documentation

typedef std::map<NCBeam::Info, PIDSpectrum*> NCExtrapolationPID::SpecMap
 

Definition at line 25 of file NCExtrapolationPID.h.


Constructor & Destructor Documentation

NCExtrapolationPID::NCExtrapolationPID POTMap dataNear,
POTMap mcNear,
POTMap dataFar,
POTMap mcFar
 

Definition at line 34 of file NCExtrapolationPID.cxx.

References PrintMap().

00038 : NCExtrapolation(dataNear, mcNear, dataFar, mcFar),
00039   useCCEnergy(true), useSelectionEnergy(true), trueBinFactor(5), nPIDBins(20),
00040   PIDmin(0.2), PIDmax(1.1),
00041   mcInFilename(""), mcOutFilename(""),
00042   doFarNearCorrection(true), emulateFarNear(false)
00043 {
00044   PrintMap(dataNear, "dataNear");
00045   PrintMap(mcNear, "mcNear");
00046   PrintMap(dataFar, "dataFar");
00047   PrintMap(mcFar, "mcFar");
00048 }

NCExtrapolationPID::~NCExtrapolationPID  )  [virtual]
 

Definition at line 52 of file NCExtrapolationPID.cxx.

References spectra.

00053 {
00054   for (SpecMap::iterator it=spectra.begin(); it!=spectra.end(); ++it)
00055     delete it->second;
00056 }


Member Function Documentation

void NCExtrapolationPID::AddEvent NCEventInfo  eventInfo,
bool  useMCAsData,
NCType::EFileType  fileType,
NCBeam::Info  beamInfo
[virtual]
 

Reimplemented from NCExtrapolation.

Definition at line 71 of file NCExtrapolationPID.cxx.

References NCExtrapolation::AddEvent(), NCEventInfo::analysis, ANtpHeaderInfo::dataType, ANtpHeaderInfo::detector, Detector::Detector_t, doFarNearCorrection, emulateFarNear, NCBeam::Info::GetDescription(), GetMCScaleFactor(), NCEventInfo::header, ANtpRecoInfo::inFiducialVolume, ANtpAnalysisInfo::isCC, ANtpRecoInfo::isCleanHighMultSnarl, ANtpAnalysisInfo::isNC, mcInFilename, nPIDBins, ANtpRecoInfo::nuEnergy, ANtpRecoInfo::nuEnergyCC, ANtpRecoInfo::nuEnergyNC, PIDmax, PIDmin, NCEventInfo::reco, ANtpAnalysisInfo::separationParameterCut, spectra, trueBinFactor, NCEventInfo::truth, useCCEnergy, useSelectionEnergy, and ANtpRecoInfo::weight.

00075 {
00076   // This call fills the NCBeam objects with the event. We don't need it
00077   // for the fit, but it does make some pretty plots at the end.
00078   NCExtrapolation::AddEvent(info, useMCAsData, fileType, beamInfo);
00079 
00080   // Some events don't get into the NC or the CC spectrum - exclude
00081   // them if we're emulating the FarNear method
00082   if (emulateFarNear &&
00083       !(info.analysis->isNC || info.analysis->isCC)) return;
00084 
00085   // Add the necessary spectrum for this beam if it's not already there
00086   if (spectra.find(beamInfo)==spectra.end()) {
00087     // If this happened when we got our MC spectra from disk,
00088     // something is probably wrong
00089     assert(mcInFilename=="");
00090 
00091     string name = string("PID_") + beamInfo.GetDescription().Data();
00092     if (emulateFarNear){
00093       spectra[beamInfo]=new PIDSpectrum(name, "title",
00094                                         nPIDBins, PIDmin, PIDmax, // PID bins
00095                                         // nPIDBins will be -1 if emulating FarNear
00096                                         trueBinFactor, beamInfo,
00097                                         info.analysis->separationParameterCut);
00098       spectra[beamInfo]->setDoFarNearCorrection(doFarNearCorrection);
00099     }
00100     else{
00101       spectra[beamInfo]=new PIDSpectrum(name, "title",
00102                                         nPIDBins, PIDmin, PIDmax, // PID bins
00103                                         trueBinFactor, beamInfo);
00104       spectra[beamInfo]->setDoFarNearCorrection(doFarNearCorrection);
00105     }
00106   }
00107 
00108   // If we loaded the spectra from file, we don't need to add any MC
00109   // events.  But add fake data events in the far detector - this
00110   // isn't the main use case, but it is useful for testing
00111   if (mcInFilename!="" &&
00112       (info.header->detector==Detector::kNear ||
00113        (info.header->dataType==SimFlag::kMC && !useMCAsData))) return;
00114 
00115   if(!fUseNC && info.analysis->isNC) return;
00116   if(!fUseCC && info.analysis->isCC) return;
00117 
00118   if (!info.reco->inFiducialVolume) return;
00119 
00120   Detector::Detector_t det=Detector::Detector_t(info.header->detector);
00121   if (det==Detector::kNear && !info.reco->isCleanHighMultSnarl) return;
00122 
00123   double energy;
00124   if (useSelectionEnergy) {
00125     energy=info.reco->nuEnergy;
00126   } else {
00127     energy=useCCEnergy ? info.reco->nuEnergyCC : info.reco->nuEnergyNC;
00128   }
00129 
00130   if (info.header->dataType==SimFlag::kData || useMCAsData) {
00131     // For fake data, reco->weight contains all the scaling we need (including POT)
00132     spectra[beamInfo]->fillData(det,
00133                                 info.truth, info.reco, info.analysis, energy,
00134                                 info.reco->weight);
00135   } else {
00136     const double mcScale=GetMCScaleFactor(beamInfo, det);
00137 
00138     spectra[beamInfo]->fillMC(det,
00139                               info.truth, info.reco, info.analysis, energy,
00140                               mcScale*info.reco->weight);
00141   }
00142 
00143 }

void NCExtrapolationPID::CleanupSpectra std::vector< TH1 * >  exps,
std::vector< TH1 * >  obss
[virtual]
 

Called after FindSpectraForPars() to delete necessary spectra.

Parameters:
exps The expected spectra just returned from FindSpectraForPars()
obss The observed spectra just returned from FindSpectraForPars()

Reimplemented from NCExtrapolation.

Definition at line 217 of file NCExtrapolationPID.cxx.

00218 {
00219   // TODO - lots of time goes into deleting histograms.
00220   for (unsigned int n = 0; n < exp.size(); ++n) delete exp[n];
00221 }

const Registry & NCExtrapolationPID::DefaultConfig  )  [static]
 

Return a default config that will be merged with the NCExtrapolationModule DefaultConfig.

Reimplemented from NCExtrapolation.

Definition at line 368 of file NCExtrapolationPID.cxx.

References Registry::LockValues(), Registry::Set(), and Registry::UnLockValues().

Referenced by Prepare().

00369 {
00370   static Registry r;
00371 
00372   r.UnLockValues();
00373 
00374   // Energy measure to use. Can be "CC", "NC" or "Selection" (which
00375   // uses NC or CC based on the event type given by the selection)
00376   r.Set("PIDFitEnergyType",   "CC");
00377 
00378   // Number of bins in PID to use
00379   r.Set("PIDFitPIDNbins",          20);
00380   // Minimum, maximum value of PID
00381   r.Set("PIDFitPIDmin",          0.2);
00382   r.Set("PIDFitPIDmax",          1.1);
00383 
00384   // How much finer to make the true energy binning than the reco
00385   // energy binning in the PIDSpectrum objects
00386   r.Set("PIDFitTrueBinFactor",   5);
00387 
00388   // The file to read the MC spectra from/write them to
00389   r.Set("PIDFitWriteMCToFile", "");
00390   r.Set("PIDFitReadMCFromFile", "");
00391 
00392   // Whether to do the far/near correction
00393   r.Set("PIDFitDoFarNearCorrection", true);
00394 
00395   // Emulate the FarNear method - overrides the number of bins setting
00396   // and the energy type if set to true
00397   r.Set("PIDFitEmulateFarNear", false);
00398 
00399   r.LockValues();
00400   return r;
00401 
00402 }

void NCExtrapolationPID::DoneFilling  )  [virtual]
 

Call this when done with filling the MC and data: normalizes the true-to-reco maps, along with anything else that needs doing. This calls DoneFillingOneBeam() for each beam

Reimplemented from NCExtrapolation.

Definition at line 343 of file NCExtrapolationPID.cxx.

References DoneFillingOneBeam(), mcInFilename, and spectra.

00344 {
00345   cout << "NCExtrapolationPID::DoneFilling()" << endl;
00346   // Only need to do this if we didn't load the spectra from file
00347   if(mcInFilename == ""){
00348     for (SpecMap::iterator sit=spectra.begin(); sit!=spectra.end(); ++sit) {
00349       DoneFillingOneBeam(sit->first);
00350     }
00351   }
00352 }

void NCExtrapolationPID::DoneFillingOneBeam NCBeam::Info  beamInfo  )  [protected]
 

See also:
DoneFilling()

Definition at line 356 of file NCExtrapolationPID.cxx.

References NCBeam::Info::GetDescription(), and spectra.

Referenced by DoneFilling().

00357 {
00358   cout << "NCExtrapolationPID::DoneFillingOneBeam("
00359        << beamInfo.GetDescription() << ")" << endl;
00360 
00361   cout << "Normalizing true-to-recos" << endl;
00362   spectra[beamInfo]->normalizeTrueToRecos();
00363 
00364 }

vector< TCanvas * > NCExtrapolationPID::DrawSpectra const NC::OscProb::OscPars coords,
string  suffix = ""
[protected]
 

Draw all the spectra.

Definition at line 301 of file NCExtrapolationPID.cxx.

References PIDSpectrum::drawEnergySlices(), PIDSpectrum::drawNearSpectra(), PIDSpectrum::drawPIDSlices(), PIDSpectrum::drawSpectrum(), PIDSpectrum::getBeamInfo(), NCBeam::Info::IsNominal(), and spectra.

Referenced by WriteSpectra().

00303 {
00304   vector<TCanvas*> v;
00305 
00306   for (SpecMap::iterator sit=spectra.begin(); sit!=spectra.end(); ++sit) {
00307     PIDSpectrum* spec=sit->second;
00308     // Drawing spectra seems to be really slow. So for now only do it
00309     // for unshifted beams.
00310     if(!spec->getBeamInfo().IsNominal()) continue;
00311     v.push_back( spec->drawSpectrum(coords, suffix) );
00312 
00313     vector<TCanvas*> vNear=spec->drawNearSpectra(suffix);
00314     vector<TCanvas*> vE=spec->drawEnergySlices(coords, suffix);
00315     vector<TCanvas*> vPID=spec->drawPIDSlices(coords, suffix);
00316 
00317     v.insert(v.end(), vE.begin(),    vE.end());
00318     v.insert(v.end(), vPID.begin(),  vPID.end());
00319     v.insert(v.end(), vNear.begin(), vNear.end());
00320   }
00321 
00322   return v;
00323 }

bool NCExtrapolationPID::EnableNearToFarExtrapolation bool  enable  )  [virtual]
 

Enable or disable corrections to FD spectra based on ND spectra.

enable true to perform extrapolation. false to give produce unextrapolated spectra

Returns:
The previous value of this setting
The default value of this setting should be to true

Reimplemented from NCExtrapolation.

Definition at line 476 of file NCExtrapolationPID.cxx.

References doFarNearCorrection, and spectra.

00477 {
00478   for(SpecMap::iterator it = spectra.begin(); it != spectra.end(); ++it)
00479     it->second->setDoFarNearCorrection(enable);
00480 
00481   const bool ret = doFarNearCorrection;
00482   doFarNearCorrection = enable;
00483   return ret;
00484 }

void NCExtrapolationPID::FindSpectraForPars const NC::OscProb::OscPars oscPars,
const NC::SystPars systPars,
std::vector< NCBeam::Info beamsToUse,
std::vector< TH1 * > &  exps,
std::vector< TH1 * > &  obss
[virtual]
 

Override this in the derived class.

Parameters:
oscPars Oscillation parameters
systPars Systematic shifts
beamsToUse Only fill exps and obss with spectra from beams with these indices
out] exps To be filled with expected spectra
out] obss To be filled with the corresponding observed spectra

Implements NCExtrapolation.

Definition at line 147 of file NCExtrapolationPID.cxx.

References GetExpHists(), NC::SpectrumInterpolator::GetInterpolatedSpectra(), GetNearMCSpectra(), GetObsHists(), NCExtrapolation::InitializeInterpolator(), NC::SpectrumInterpolator::MultiplyFast(), s(), and NC::CoordinateConverter::VectorFromSystPars().

00152 {
00153   if(fDoSystematicInterpolation) InitializeInterpolator(pars);
00154 
00155   if(!fInterpolator){
00156     exps = GetExpHists(beamsToUse, pars);
00157     obss = GetObsHists(beamsToUse);
00158     return;
00159   }
00160 
00161 
00162   const vector<double> shift = fCoordConv.VectorFromSystPars(s);
00163 
00164   vector<TH1*> interp = fInterpolator->GetInterpolatedSpectra(shift);
00165 
00166   vector<TH1*> nd_ratios;
00167   assert(interp.size()%2 == 0); // Every FD has a corresponding ND
00168   // The ND ratios are the second half of the vector. Copy them out.
00169   for(unsigned int n = interp.size()/2; n < interp.size(); ++n)
00170     nd_ratios.push_back(interp[n]);
00171 
00172   vector<const TH1*> tmp = GetNearMCSpectra(beamsToUse);
00173 
00174   assert(nd_ratios.size() == tmp.size());
00175 
00176   vector<TH1*> nd_spectra;
00177   for(unsigned int n = 0; n < tmp.size(); ++n){
00178     nd_spectra.push_back(NC::SpectrumInterpolator::CloneFast(tmp[n]));
00179     NC::SpectrumInterpolator::MultiplyFast(nd_spectra[n], nd_ratios[n]);
00180   }
00181   assert(nd_spectra.size() == tmp.size());
00182 
00183   // Pass nd_spectra to GetExpHists so the FD spectra take account of ND shifts
00184   exps = GetExpHists(beamsToUse, pars, nd_spectra);
00185   // Get observed spectra - no interpolation needs to be done on these
00186   obss = GetObsHists(beamsToUse);
00187 
00188   assert(interp.size() == 2*exps.size());
00189   // The FD ratios are on the front of the vector, so their indices correspond
00190   // to those in 'exps'
00191   for(unsigned int n = 0; n < exps.size(); ++n)
00192     NC::SpectrumInterpolator::MultiplyFast(exps[n], interp[n]);
00193 
00194   // TODO - deleting spectra takes silly amounts of time
00195   for(unsigned int n = 0; n < interp.size(); ++n) delete interp[n];
00196 }

vector< TH1 * > NCExtrapolationPID::GetExpHists vector< NCBeam::Info beamsToUse,
const NC::OscProb::OscPars coords,
std::vector< TH1 * >  ndSpectra = vector< TH1 * >()
const [protected]
 

Get the expected histograms in the format required for NCUtils' log likelihood method.

Definition at line 269 of file NCExtrapolationPID.cxx.

References spectra.

Referenced by FindSpectraForPars().

00272 {
00273   vector<TH1*> expHists;
00274   for (int i=0; i<(int)beamsToUse.size(); ++i) {
00275     NCBeam::Info beamInfo=beamsToUse[i];
00276     SpecMap::const_iterator spectrumForBeamInfo=spectra.find(beamInfo);
00277     assert(spectrumForBeamInfo!=spectra.end());
00278     assert(spectrumForBeamInfo->second);
00279     expHists.push_back(spectrumForBeamInfo->second->getPredicted(pars, "", ndSpectra.empty() ? 0 : ndSpectra[i]));
00280   }
00281 
00282   return expHists;
00283 }

virtual TString NCExtrapolationPID::GetLongName  )  const [inline, virtual]
 

This is the name the extrapolation is known under on plots and such.

Implements NCExtrapolation.

Definition at line 59 of file NCExtrapolationPID.h.

00059 { return "2d PID fit"; }

double NCExtrapolationPID::GetMCScaleFactor const NCBeam::Info info,
Detector::Detector_t  det
[protected]
 

Factor to scale MC by to make it match data.

Definition at line 60 of file NCExtrapolationPID.cxx.

References Detector::Detector_t, and NCExtrapolation::GetPOTForBeam().

Referenced by AddEvent().

00062 {
00063   double dataPOT, mcPOT;
00064   GetPOTForBeam(info, det, dataPOT, mcPOT);
00065   return dataPOT/mcPOT;
00066 }

vector< const TH1 * > NCExtrapolationPID::GetNearMCSpectra std::vector< NCBeam::Info beamsToUse  )  [virtual]
 

Reimplemented from NCExtrapolation.

Definition at line 201 of file NCExtrapolationPID.cxx.

References spectra.

Referenced by FindSpectraForPars().

00202 {
00203   vector<const TH1*> expHists;
00204   for (int i=0; i<(int)beamsToUse.size(); ++i) {
00205     NCBeam::Info beamInfo=beamsToUse[i];
00206     SpecMap::const_iterator spectrumForBeamInfo=spectra.find(beamInfo);
00207     assert(spectrumForBeamInfo!=spectra.end());
00208     assert(spectrumForBeamInfo->second);
00209     expHists.push_back(spectrumForBeamInfo->second->getNearMC());
00210   }
00211 
00212   return expHists;
00213 }

vector< TH1 * > NCExtrapolationPID::GetObsHists vector< NCBeam::Info beamsToUse  )  const [protected]
 

Get the observed histograms in the format required for NCUtils' log likelihood method.

Definition at line 287 of file NCExtrapolationPID.cxx.

References spectra.

Referenced by FindSpectraForPars().

00289 {
00290   vector<TH1*> obsHists;
00291   for (int i=0; i<(int)beamsToUse.size(); ++i) {
00292     NCBeam::Info beamInfo=beamsToUse[i];
00293     obsHists.push_back(spectra.find(beamInfo)->second->getDataHist());
00294   }
00295 
00296   return obsHists;
00297 }

virtual TString NCExtrapolationPID::GetShortName  )  const [inline, virtual]
 

This is the name used to name things in the output file etc.

Implements NCExtrapolation.

Definition at line 58 of file NCExtrapolationPID.h.

00058 { return "PID"; }

void NCExtrapolationPID::Prepare const Registry r  )  [virtual]
 

Read whatever values you need out of the registry to initialize yourself. Please remember to chain up to the NCExtrapolation implementation too.

Reimplemented from NCExtrapolation.

Definition at line 406 of file NCExtrapolationPID.cxx.

References DefaultConfig(), doFarNearCorrection, emulateFarNear, Registry::Get(), Registry::GetInt(), mcInFilename, mcOutFilename, nPIDBins, PIDmax, PIDmin, NCExtrapolation::Prepare(), ReadMCSpectra(), spectra, trueBinFactor, useCCEnergy, and useSelectionEnergy.

00407 {
00408   NCExtrapolation::Prepare(r);
00409 
00410   cout << "NCExtrapolationPID::Prepare" << endl;
00411   const char* tmps;
00412   int tmpi;
00413   double tmpd;
00414 
00415   if (r.Get("PIDFitEnergyType", tmps)) {
00416     string energyType(tmps);
00417     assert(energyType=="NC" || energyType=="CC" || energyType=="Selection");
00418     useSelectionEnergy = (energyType=="Selection");
00419     useCCEnergy = (energyType=="CC");
00420   }
00421 
00422   if (r.Get("PIDFitPIDNbins", tmpi)) nPIDBins=tmpi;
00423 
00424   // Minimum, maximum value of PID
00425   if (r.Get("PIDFitPIDmin", tmpd)) PIDmin=tmpd;
00426   if (r.Get("PIDFitPIDmax", tmpd)) PIDmax=tmpd;
00427 
00428   cout << "nPIDBins=" << nPIDBins
00429        << " PID range=[" << PIDmin << ", " << PIDmax << "]" << endl;
00430 
00431   if (r.Get("PIDFitTrueBinFactor", tmpi))       trueBinFactor=tmpi;
00432   if (r.Get("PIDFitDoFarNearCorrection", tmpi)) doFarNearCorrection=tmpi;
00433 
00434   if (r.Get("PIDFitEmulateFarNear", tmpi)) emulateFarNear=tmpi;
00435 
00436   if (emulateFarNear) {
00437     // If we're emulating the FarNear method, we just have two PID
00438     // bins, but we use nPIDBins=-1 to signal to PIDSpectrum that it
00439     // should put the separation point where the cut value is
00440     nPIDBins=-1;
00441     useSelectionEnergy=true;
00442 
00443     if (r.Get("PIDFitPIDNbins", tmpi) &&
00444         tmpi!=DefaultConfig().GetInt("PIDFitPIDNbins"))
00445       cout << "WARNING: PIDFitPIDNbins was set, but overridden by PIDFitEmulateFarNear"
00446            << endl;
00447   }
00448 
00449   // Files to read the MC spectra from/write them to
00450   if (r.Get("PIDFitReadMCFromFile", tmps)) mcInFilename=tmps;
00451   if (r.Get("PIDFitWriteMCToFile", tmps))  mcOutFilename=tmps;
00452 
00453   if (mcInFilename!="") {
00454     ReadMCSpectra(mcInFilename.c_str());
00455     // reset the observed spectra - if we got the PIDSpectrum's from file, we'll be
00456     // filling them with mock data presumably anyway
00457     for (SpecMap::iterator sit=spectra.begin(); sit!=spectra.end(); ++sit) {
00458       TH2F* h=sit->second->getDataHist();
00459       h->Reset();
00460     }
00461   }
00462 
00463 }

void NCExtrapolationPID::PrintMap POTMap m,
const char *  name
[private]
 

Print out a POT map for debugging purposes.

Definition at line 245 of file NCExtrapolationPID.cxx.

Referenced by NCExtrapolationPID().

00246 {
00247   cout << "Map " << name << endl;
00248   for (POTMap::const_iterator it=m.begin();
00249        it!=m.end(); ++it) {
00250     cout << it->first.GetDescription() << "\t" << it->second << endl;
00251   }
00252 }

void NCExtrapolationPID::PrintSpectraMap  )  [private]
 

Definition at line 256 of file NCExtrapolationPID.cxx.

References spectra.

00257 {
00258   cout << "spectra:" << endl;
00259   for (SpecMap::const_iterator it=spectra.begin();
00260        it!=spectra.end(); ++it) {
00261     cout << it->first.GetDescription() << "\t" << hex << it->second << dec
00262          << "\t" << it->second->getBeamInfo().GetTitle() << endl;
00263   }
00264 }

void NCExtrapolationPID::ReadMCSpectra const char *  filename  )  [protected]
 

Read the MC spectra from filename, replacing the existing spectra.

Definition at line 498 of file NCExtrapolationPID.cxx.

References emulateFarNear, PIDSpectrum::getBeamInfo(), PIDSpectrum::getNPIDBins(), nPIDBins, and spectra.

Referenced by Prepare().

00499 {
00500 
00501   cout << "Reading MC spectra from file " << filename << endl;
00502   TFile f(filename);
00503 
00504   TList *l = f.GetListOfKeys();
00505   TIter it(l);
00506   TObject *obj;
00507   TKey* k;
00508   while (( k=(TKey*)it() )) {
00509     obj=f.Get(k->GetName());
00510     cout << "Trying object " << obj->GetName() << endl;
00511     if (! (obj->IsA() == PIDSpectrum::Class()) ) {
00512       cerr << "Object with name " << obj->GetName() << " not a PIDSpectrum. Bailing" << endl;
00513       exit(1);
00514     }
00515     cout << "...object is a PIDSpectrum. Adding to list" << endl;
00516     PIDSpectrum* p=(PIDSpectrum*)obj;
00517 
00518     // nPIDBins is mangled when using emulateFarNear, so need this branch
00519     if (emulateFarNear) assert(p->getNPIDBins()==2);
00520     else                assert(p->getNPIDBins()==nPIDBins);
00521 
00522     spectra[p->getBeamInfo()]=p;
00523   }
00524 
00525 }

void NCExtrapolationPID::Reset bool  nearData,
bool  farData,
bool  nearMC,
bool  farMC
[virtual]
 

Causes the extrapolation to forget everything it knows about the requested spectra.

This implementation clears the relevant NCBeam objects

Derived classes please override if you handle spectra yourself

Reimplemented from NCExtrapolation.

Definition at line 466 of file NCExtrapolationPID.cxx.

References spectra.

00468 {
00469   for (SpecMap::iterator sit=spectra.begin(); sit!=spectra.end(); ++sit) {
00470     if(farData) sit->second->resetData();
00471     if(farMC) sit->second->resetMC();
00472   }
00473 }

void NCExtrapolationPID::WriteMCSpectra const char *  filename  )  [protected]
 

Save the unoscillated MC spectra to filename so they can be.

Definition at line 488 of file NCExtrapolationPID.cxx.

References spectra.

Referenced by WriteResources().

00489 {
00490   TFile f(filename, "RECREATE");
00491   for (SpecMap::iterator sit=spectra.begin(); sit!=spectra.end(); ++sit) {
00492     sit->second->Write();
00493   }
00494 }

void NCExtrapolationPID::WriteResources const NC::OscProb::OscPars trueOscPars  )  [virtual]
 

gDirectory will point to the output file. Please remember to chain up to the NCExtrapolation implementation.

trueOscPars may be zero (eg obviously in case of fit to real data)

Reimplemented from NCExtrapolation.

Definition at line 226 of file NCExtrapolationPID.cxx.

References NCExtrapolation::GetBestFitOscPars(), mcOutFilename, WriteMCSpectra(), NCExtrapolation::WriteResources(), and WriteSpectra().

00227 {
00228   NCExtrapolation::WriteResources(trueOscPars);
00229 
00230   // Store my plots in a debug directory
00231   gDirectory->mkdir("debug", "debug")->cd();
00232 
00233   NC::OscProb::OscPars* bestFit=GetBestFitOscPars();
00234 
00235   if(bestFit) WriteSpectra(bestFit, "_bestFit");
00236 
00237   if(trueOscPars) WriteSpectra(trueOscPars, "_truePars");
00238 
00239   // If requested, save the PIDSpectrum objects out to file
00240   if (mcOutFilename!="") WriteMCSpectra(mcOutFilename.c_str());
00241 }

void NCExtrapolationPID::WriteSpectra const NC::OscProb::OscPars coords,
string  suffix = ""
[protected]
 

Write the spectra, evaluated at the parameters coords, prettily to gDirectory.

Definition at line 327 of file NCExtrapolationPID.cxx.

References DrawSpectra().

Referenced by WriteResources().

00328 {
00329   vector<TCanvas*> v=DrawSpectra(coords, suffix);
00330   for (vector<TCanvas*>::iterator it=v.begin();
00331        it!=v.end(); ++it) {
00332     (*it)->Write();
00333   }
00334 
00335   // Also get the histograms of the tau component
00336   // (for the "can we see taus?" study)
00337   //for (SpecMap::iterator sit=spectra.begin(); sit!=spectra.end(); ++sit)
00338   //  sit->second->getOnePredicted(PIDSpectrum::kNutau, coords, suffix.c_str())->Write();
00339 }


Member Data Documentation

bool NCExtrapolationPID::doFarNearCorrection [protected]
 

Whether to do the far/near correction.

Definition at line 140 of file NCExtrapolationPID.h.

Referenced by AddEvent(), EnableNearToFarExtrapolation(), and Prepare().

bool NCExtrapolationPID::emulateFarNear [protected]
 

Whether to emulate the Far/Near method by having just two bins.

Definition at line 146 of file NCExtrapolationPID.h.

Referenced by AddEvent(), Prepare(), and ReadMCSpectra().

string NCExtrapolationPID::mcInFilename [protected]
 

The filename to read the MC spectra from.

Definition at line 134 of file NCExtrapolationPID.h.

Referenced by AddEvent(), DoneFilling(), and Prepare().

string NCExtrapolationPID::mcOutFilename [protected]
 

The filename to write the MC spectra to.

Definition at line 137 of file NCExtrapolationPID.h.

Referenced by Prepare(), and WriteResources().

int NCExtrapolationPID::nPIDBins [protected]
 

How many bins in PID to use.

Definition at line 125 of file NCExtrapolationPID.h.

Referenced by AddEvent(), Prepare(), and ReadMCSpectra().

double NCExtrapolationPID::PIDmax [protected]
 

The maximum value of PID to use.

Definition at line 131 of file NCExtrapolationPID.h.

Referenced by AddEvent(), and Prepare().

double NCExtrapolationPID::PIDmin [protected]
 

The minimum value of PID to use.

Definition at line 128 of file NCExtrapolationPID.h.

Referenced by AddEvent(), and Prepare().

SpecMap NCExtrapolationPID::spectra [protected]
 

The 2D spectra, indexed by beam.

Definition at line 105 of file NCExtrapolationPID.h.

Referenced by AddEvent(), DoneFilling(), DoneFillingOneBeam(), DrawSpectra(), EnableNearToFarExtrapolation(), GetExpHists(), GetNearMCSpectra(), GetObsHists(), Prepare(), PrintSpectraMap(), ReadMCSpectra(), Reset(), WriteMCSpectra(), and ~NCExtrapolationPID().

int NCExtrapolationPID::trueBinFactor [protected]
 

How much finer to make the true energy binning than the reco.

Definition at line 122 of file NCExtrapolationPID.h.

Referenced by AddEvent(), and Prepare().

bool NCExtrapolationPID::useCCEnergy [protected]
 

Whether to use the CC energy estimator. If false, use NC energy estimator. useSelectionEnergy overrides this

Definition at line 111 of file NCExtrapolationPID.h.

Referenced by AddEvent(), and Prepare().

bool NCExtrapolationPID::useSelectionEnergy [protected]
 

Whether to use the event energy as defined by NCUtils - ie CC energy if event is selected CC and NC energy if event is selected NC. Overrides useCCEnergy

Definition at line 118 of file NCExtrapolationPID.h.

Referenced by AddEvent(), and Prepare().


The documentation for this class was generated from the following files:
Generated on Mon Feb 9 22:58:06 2009 for loon by doxygen 1.3.5