NCExtrapolationModule Class Reference

Job module to perform extrapolations and fits. More...

#include <NCExtrapolationModule.h>

List of all members.

Public Member Functions

 NCExtrapolationModule ()
virtual ~NCExtrapolationModule ()
const RegistryDefaultConfig () const
void Config (const Registry &r)
void Run ()
void SetMCExposureForBeam (NCBeam::Info beam, double pot)
virtual void AddEventToExtrapolations (bool fakeDataSet)
 Add event held in fEventInfo to all extrapolations.

Static Public Member Functions

static void AddExtrapolation (NCExtrapolationFactory *e)

Private Types

typedef std::map< NCBeam::Info,
TChain * > 
ChainMap
typedef std::map< NCBeam::Info,
double > 
POTMap

Private Member Functions

TH1 * CreateSpecialPlot (int k, TString type) const
void PrepareForExtrapolation ()
void GetListOfShifts (std::vector< bool * > &useParameters, std::vector< std::vector< double > > &adjustedValues) const
void AddShiftedEventToExtrapolations (NCEventInfo eventInfo, bool useMCAsData, NCType::EFileType fileType, NC::RunUtil::ERunType runType, NCBeam::Info beamInfo)
void AddFilesToChain (ChainMap &chainMap, Detector::Detector_t det, NCType::EFileType fileType, NCType::EDataMC dataMC)
 Add relevant files for some spectrum to chainMap.
void ExtrapolateNearToFar ()
 Add the FD events to the extrapolations and run the fit for each one.
void FillDataQualityPlotsSpecial (std::vector< TH1 * > &dq, bool osc)
void DoMockExperiments ()
void SystematicsFromRegistry (bool *systematicsToUse, std::vector< double > &systematicsAdjust)
void ApplySystematicShifts (NC::RunUtil::ERunType runType)
double GetMCScaleFactor (Detector::Detector_t det, NCType::EFileType fileType, NCBeam::Info info)
 Get the factor to scale the MC by to match the data. Will be zero for beams which have no data.
double GetScaleFactorFromMaps (POTMap &potData, POTMap &potMC, NCBeam::Info info)
 Helper for GetMCScaleFactor.
void SetEventWeight (BeamType::BeamType_t beamType, NC::RunUtil::ERunType runType, bool fakeDataSet)
bool FinalEventCheck ()
 any last checks.
void SetEnergies ()
 Set reco.nuEnergy and reco.showerEnergy to the appropriate NC or CC variant.
void DrawDataQualityPlots ()
void DrawDataQualityPlotsSpecial ()
void CreateExtrapolations (TString extrapolations)

Static Private Member Functions

static std::vector< NCExtrapolationFactory * > & GetExtrapolationFactories ()
 The various extrapolations that have registered themselves.

Private Attributes

NC::OscProb::OscParsfTrueOscPars
std::vector< TH1 * > fDQNearMCTotalSpecial
TString fDataMCPath
 path to uDST for data and MC files
TString fFileName
 name of output file
bool fUseMCAsData
 use the MC as data for testing purposes
NCType::EOscModel fOscillationModel
 model to use in the fit
NCType::EExtraction fExtractionType
 the extraction to use
bool fUseMockData
 are you using mock data for the data?
std::vector< BeamType::BeamType_tfBeamIndex
 index of beams to use
bool fUsePIDCustomCut
 Use custom cut.
double fPIDCustomCut
 Custom cut value.
bool fShiftedBeams
 If set then AddShiftedEventToExtrapolations is called.
bool fSimpleShiftedBeams
 Controls whether to generate a simpler set of shifted beams.
int fSingleShiftedBeam
 Controls if only a single shifted beam is made.
bool fMakeDQPlotsSpecial
 Ask Alex...
NCEventInfo fEventInfo
std::vector< NCExtrapolation * > fExtrapolations
std::vector< NC::FitMaster * > fFitMasters
TString fExtrapolationsList
 A space-separated list of extrapolations to use, from job macro.
TString fLoadExtrapolationsFile
 Filename to load extrapolation objects from. Empty string -> no loading.
bool fIncludeDataFromLoadedExtrapolations
 If fLoadExtrapolationsFile then load data part of spectrum too.
TString fSaveExtrapolationsFile
 Filename to save extrapolation objects to. Empty string -> no saving.
bool fSingleSpectrum
 use a single spectrum
std::vector< NC::RunUtil::ERunTypefRunsToUse
 define which runs to use
POTMap fDataPOTNear
POTMap fDataPOTFar
POTMap fMCPOTNear
POTMap fMCPOTFar
POTMap fMCPOTFarTau
POTMap fMCPOTFarElectron
int fNumMockExperiments
 Zero if fake experiments are not to be carried out (default).
int fMockExperimentsSeed
std::vector< NCEventInfo * > fFDMCSample
NCPOTCounterfPOTCount
std::vector< Registry * > fMockFits
Registry fConfig


Detailed Description

Job module to perform extrapolations and fits.

Definition at line 61 of file NCExtrapolationModule.h.


Member Typedef Documentation

typedef std::map<NCBeam::Info, TChain*> NCExtrapolationModule::ChainMap [private]

Definition at line 85 of file NCExtrapolationModule.h.

typedef std::map<NCBeam::Info, double> NCExtrapolationModule::POTMap [private]

Definition at line 86 of file NCExtrapolationModule.h.


Constructor & Destructor Documentation

NCExtrapolationModule::NCExtrapolationModule (  ) 

Definition at line 46 of file NCExtrapolationModule.cxx.

References NCEventInfo::analysis, NCEventInfo::beam, CreateSpecialPlot(), fDQNearMCTotalSpecial, fEventInfo, fPOTCount, NCEventInfo::header, Msg::kDebug, MSG, NCEventInfo::reco, and NCEventInfo::truth.

00046                                              :
00047   fTrueOscPars(0),
00048   fNumMockExperiments(0),
00049   fPOTCount(0)
00050 {
00051   MSG("JobC", Msg::kDebug) << "NCExtrapolationModule::Constructor" << endl;
00052 
00053   // "Special" means studying systematic shifts.
00054   // These are the TOm selection variables.
00055   for(int k = 3; k < 6; ++k){
00056     fDQNearMCTotalSpecial.push_back(CreateSpecialPlot(k, "NearMCTotalSpecial"));
00057   }
00058 
00059   fEventInfo.header = new ANtpHeaderInfo;
00060   fEventInfo.beam = new ANtpBeamInfo;
00061   fEventInfo.reco = new ANtpRecoInfo;
00062   fEventInfo.analysis = new ANtpAnalysisInfo;
00063   fEventInfo.truth = new ANtpTruthInfoBeam;
00064 
00065   fPOTCount = new NCPOTCounter;
00066 }

NCExtrapolationModule::~NCExtrapolationModule (  )  [virtual]

Definition at line 111 of file NCExtrapolationModule.cxx.

References NCEventInfo::analysis, NCEventInfo::beam, fEventInfo, fExtrapolations, fFDMCSample, fFitMasters, fMockFits, fPOTCount, fTrueOscPars, header, NCEventInfo::header, Msg::kDebug, MSG, NCEventInfo::reco, NCEventInfo::reco_nom, and NCEventInfo::truth.

00112 {
00113   MSG("JobC", Msg::kDebug) << "NCExtrapolationModule::Destructor" << endl;
00114 
00115   for(unsigned int n = 0; n < fExtrapolations.size(); ++n) delete fExtrapolations[n];
00116   for(unsigned int n = 0; n < fFitMasters.size(); ++n) delete fFitMasters[n];
00117 
00118   if(fEventInfo.header) delete fEventInfo.header;
00119   if(fEventInfo.beam) delete fEventInfo.beam;
00120   if(fEventInfo.reco) delete fEventInfo.reco;
00121   if(fEventInfo.reco_nom) delete fEventInfo.reco_nom;
00122   if(fEventInfo.truth) delete fEventInfo.truth;
00123   if(fEventInfo.analysis) delete fEventInfo.analysis;
00124 
00125   if(fTrueOscPars) delete fTrueOscPars;
00126 
00127   if(fPOTCount) delete fPOTCount;
00128 
00129   for(unsigned int n = 0; n < fFDMCSample.size(); ++n){
00130     delete fFDMCSample[n]->header;
00131     delete fFDMCSample[n]->beam;
00132     delete fFDMCSample[n]->reco;
00133     delete fFDMCSample[n]->reco_nom;
00134     delete fFDMCSample[n]->truth;
00135     delete fFDMCSample[n]->analysis;
00136     delete fFDMCSample[n];
00137   }
00138 
00139   for(unsigned int n = 0; n < fMockFits.size(); ++n) delete fMockFits[n];
00140 }


Member Function Documentation

void NCExtrapolationModule::AddEventToExtrapolations ( bool  fakeDataSet  )  [virtual]

Add event held in fEventInfo to all extrapolations.

This is the callback used by NC::IEventAdder Warning - as a side-effect may modify the details of the event although we do take care to restore the event weight properly

Note:
virtual function for testability

Definition at line 943 of file NCExtrapolationModule.cxx.

References AddShiftedEventToExtrapolations(), NCEventInfo::analysis, NCEventInfo::beam, ANtpBeamInfo::beamType, ANtpHeaderInfo::dataType, NCEventInfo::DeepCopy(), ANtpHeaderInfo::detector, MuELoss::e, fDQNearMCTotalSpecial, fEventInfo, fExtrapolations, fFDMCSample, FillDataQualityPlotsSpecial(), FinalEventCheck(), NCType::FindFileType(), NC::RunUtil::FindRunType(), fMakeDQPlotsSpecial, fNumMockExperiments, fPIDCustomCut, fShiftedBeams, fSingleSpectrum, fUsePIDCustomCut, NCEventInfo::header, ANtpTruthInfo::interactionType, ANtpAnalysisInfo::isCC, ANtpAnalysisInfo::isNC, SimFlag::kData, NCType::kElectronFile, Detector::kFar, SimFlag::kMC, NCType::kMockFile, NCType::kNC, Detector::kNear, NC::RunUtil::kRunAll, NCType::kTauFile, NCType::kUnknownFile, ANtpTruthInfoBeam::nonOscNuFlavor, NCEventInfo::reco, ANtpAnalysisInfo::separationParameter, ANtpAnalysisInfo::separationParameterCut, SetEnergies(), SetEventWeight(), NCEventInfo::truth, and ANtpRecoInfo::weight.

Referenced by NC::MockDataAdder::AddEventsToExtrapolations(), NC::RealDataAdder::AddEventsToExtrapolations(), NC::SplitFakeDataAdder::AddEventsToExtrapolations(), and NC::FakeDataAdder::AddEventsToExtrapolations().

00944 {
00945   // This is pretty much immediately after the event comes off disk. Call
00946   // SetEnergies here, as early as possible, so showerEnergy and trackEnergy
00947   // are set to the right NC/CC variants. This is certainly needed for getting
00948   // systematic shifts right, and maybe other reasons.
00949   SetEnergies();
00950 
00951   SimFlag::SimFlag_t sim = SimFlag::SimFlag_t(fEventInfo.header->dataType);
00952 
00953   //Use PID custom selection cut if so desired
00954   if(fUsePIDCustomCut &&
00955      TMath::Abs(fPIDCustomCut-fEventInfo.analysis->separationParameterCut) > 1e-3){
00956     fEventInfo.analysis->separationParameterCut = fPIDCustomCut;
00957 
00958     fEventInfo.analysis->isNC = int(fEventInfo.analysis->separationParameter
00959                                     < fPIDCustomCut);
00960     fEventInfo.analysis->isCC = int(fEventInfo.analysis->separationParameter
00961                                     >= fPIDCustomCut);
00962   }
00963 
00964   //check for any extra cuts you may want to apply, eg good shower cut
00965   if(!FinalEventCheck()) return;
00966 
00967   //check if the event is from a tau file.
00968   const NCType::EFileType fileType = NCType::FindFileType(fEventInfo.header);
00969   const NC::RunUtil::ERunType runType  = NC::RunUtil::FindRunType(fEventInfo.header,
00970                                                                   fEventInfo.reco);
00971 
00972   if(fileType == NCType::kTauFile ||
00973      fileType == NCType::kElectronFile){
00974     //dont add in NC tau or nue appearance
00975     //events as you cant distinguish flavor
00976     //with NC events.  NCEnergyBin wouldnt
00977     //accept the event anyway.  also reject
00978     //events from these files that start off as
00979     //nue...just say they dont oscillate as
00980     //they dont contribute much anyway
00981     if(fEventInfo.truth->interactionType == NCType::kNC ||
00982        TMath::Abs(fEventInfo.truth->nonOscNuFlavor) == 12) return;
00983   }
00984   else if(fileType == NCType::kUnknownFile) return;
00985 
00986   // Single spectrum fitting
00987   if(fSingleSpectrum){
00988     fEventInfo.analysis->isNC = 0;
00989     fEventInfo.analysis->isCC = 1;
00990   }
00991 
00992 
00993   if(sim == SimFlag::kData || fileType == NCType::kMockFile)
00994     fEventInfo.truth = 0;
00995 
00996   // Mock data should have simflag set to data
00997   if (fileType == NCType::kMockFile)
00998     fEventInfo.header->dataType=SimFlag::kData;
00999 
01000   //--------------------------------------------------------------------------------
01001   //put in for testing purposes, should be commented out for real fits
01002   //if(TMath::Abs(fEventInfo.truth->nuFlavor) == 12) continue;
01003   //     fEventInfo.analysis->isNC = 0;
01004   //     fEventInfo.analysis->isCC = 0;
01005   //     if(fEventInfo.truth->interactionType < 1) fEventInfo.analysis->isNC = 1;
01006   //     else if(fEventInfo.truth->interactionType > 0) fEventInfo.analysis->isCC = 1;
01007   //     fEventInfo.reco->nuEnergy = truthInfo->nuEnergy;
01008   //--------------------------------------------------------------------------------
01009 
01010   // TODO - correct if statement?
01011   if(sim == SimFlag::kMC && fakeDataSet &&
01012      fEventInfo.header->detector == Detector::kFar &&
01013      fNumMockExperiments > 0){
01014     NCEventInfo* evt = new NCEventInfo;
01015     evt->DeepCopy(&fEventInfo);
01016 
01017     fFDMCSample.push_back(evt);
01018   }
01019 
01020   const BeamType::BeamType_t beamType =
01021     (BeamType::BeamType_t)(fEventInfo.beam->beamType);
01022   const NCBeam::Info beamInfo(beamType, runType);
01023   const NCBeam::Info infoAll(beamType, NC::RunUtil::kRunAll);
01024 
01025 
01026   //add event to each extrapolation
01027   for(unsigned int i = 0; i < fExtrapolations.size(); ++i){
01028     if(sim==SimFlag::kMC){
01029         SetEventWeight(beamType, runType, fakeDataSet);
01030 
01031         // If we have MC for this beam but not data, SetEventWeight
01032         // will have set the weight to zero, so don't add it at
01033         // all. This ensures that the MC beams that have events added
01034         // to them are the ones that were selected in the RunsToUse
01035         // registry key *and* have data available
01036         if(fEventInfo.reco->weight!=0){
01037           
01038           //NCBeam::Info info=NCBeam::Info(beamType, thisRunType);
01039           fExtrapolations[i]->AddEvent(fEventInfo, fakeDataSet,
01040                                        fileType, beamInfo);
01041           // Also add it to the RunAll beam
01042           fExtrapolations[i]->AddEvent(fEventInfo, fakeDataSet,
01043                                        fileType, infoAll);
01044           
01045           if(fShiftedBeams){
01046             AddShiftedEventToExtrapolations(fEventInfo, fakeDataSet, fileType,
01047                                             runType, beamInfo);
01048             AddShiftedEventToExtrapolations(fEventInfo, fakeDataSet, fileType,
01049                                             runType, infoAll);
01050           }
01051 
01052         }// end if non-zero weight
01053     }// end if MC
01054     else{
01055       SetEnergies();
01056       // Data/mock data goes in whatever run it really is...
01057       fExtrapolations[i]->AddEvent(fEventInfo, fakeDataSet,
01058                                    fileType, beamInfo);
01059       // ...and RunAll
01060       fExtrapolations[i]->AddEvent(fEventInfo, fakeDataSet,
01061                                    fileType, infoAll);
01062     }
01063   }//end loop over extrapolation objects
01064 
01065 
01066   if(fMakeDQPlotsSpecial){
01067     if(fEventInfo.header->dataType == int(SimFlag::kMC)){
01068       if(fEventInfo.header->detector == int(Detector::kNear)){
01069         FillDataQualityPlotsSpecial(fDQNearMCTotalSpecial, false);
01070       }
01071     }
01072   }
01073 }

void NCExtrapolationModule::AddExtrapolation ( NCExtrapolationFactory e  )  [static]

Definition at line 340 of file NCExtrapolationModule.cxx.

References MuELoss::e, and GetExtrapolationFactories().

00341 {
00342   std::vector<NCExtrapolationFactory*>& facts = GetExtrapolationFactories();
00343   for(unsigned int n = 0; n < facts.size(); ++n){
00344     // If this happens it means that extrapolations have got registered
00345     // twice somehow. Check your environment, and rebuild stuff, including
00346     // the macro.
00347     assert(e->GetCodeName() != facts[n]->GetCodeName());
00348   }
00349   facts.push_back(e);
00350 }

void NCExtrapolationModule::AddFilesToChain ( ChainMap chainMap,
Detector::Detector_t  det,
NCType::EFileType  fileType,
NCType::EDataMC  dataMC 
) [private]

Add relevant files for some spectrum to chainMap.

Parameters:
chainMap chain to add the files to
det detector the chain represents
fileType is only relevant for MC - should be kBeamFile otherwise
dataMC whether chainMap is holding a data or MC spectrum - getting the correct fake/mock data files is taken care of by NCPOTCounter

Definition at line 499 of file NCExtrapolationModule.cxx.

References BeamType::AsString(), fDataMCPath, files, NCType::FileTypeAsString(), fPOTCount, NCPOTCounter::GetListOfFiles(), Msg::kInfo, and MSG.

Referenced by Run().

00503 {
00504   MSG("NCExtrapolationModule", Msg::kInfo) << "fDataMCPath = "
00505                                            << fDataMCPath << endl;
00506 
00507   for(ChainMap::iterator it=chainMap.begin();
00508       it != chainMap.end();
00509       ++it){
00510 
00511     const NCBeam::Info info=it->first;
00512     const TString beamType=BeamType::AsString(info.GetBeamType());
00513 
00514     vector<TString> files = fPOTCount->GetListOfFiles(info, fileType,
00515                                                       det, dataMC);
00516     
00517     for(unsigned int de = 0; de < files.size(); ++de) {
00518       it->second->Add(fDataMCPath+beamType+"/"+files[de]);
00519       MSG("NCExtrapolationModule", Msg::kInfo) 
00520         << "Adding "
00521         << fDataMCPath+beamType
00522         << "/"+files[de] << " to "
00523         << NCType::FileTypeAsString(fileType) << " chain" << endl;
00524 
00525     }//end loop over files in directory
00526   }//end loop over map
00527 }

void NCExtrapolationModule::AddShiftedEventToExtrapolations ( NCEventInfo  eventInfo,
bool  useMCAsData,
NCType::EFileType  fileType,
NC::RunUtil::ERunType  runType,
NCBeam::Info  beamInfo 
) [private]

Shift eventInfo according to all the different variations given by GetListOfShifts and each time add it to all the extrapolations.

Definition at line 1146 of file NCExtrapolationModule.cxx.

References ANtpHeaderInfo::dataType, NCEventInfo::DeepCopy(), det, ANtpHeaderInfo::detector, fEventInfo, fExtrapolations, FinalEventCheck(), fSingleShiftedBeam, GetListOfShifts(), GetMCScaleFactor(), NCEventInfo::header, NCType::kData, NCEventInfo::reco, SetEnergies(), NCEventInfo::SetEventWeight(), NCBeam::Info::SetSystShifts(), and ANtpRecoInfo::weight.

Referenced by AddEventToExtrapolations().

01151 {
01152   // No point adding/shifting data events
01153   if(eventInfo.header->dataType == NCType::kData || useMCAsData) return;
01154 
01155   Detector::Detector_t det = Detector::Detector_t(fEventInfo.header->detector);
01156   // On the assumption that the contents of the registry don't change between
01157   // successive calls to us, then save time by only working out what shifts
01158   // to do once.
01159   static vector<bool*> useParameters;
01160   static vector<vector<double> > adjustedValues;
01161   static bool once = true;
01162   if(once){
01163     once = false;
01164     GetListOfShifts(useParameters, adjustedValues);
01165   }
01166 
01167 
01168   NC::OscProb::OscPars* noosc = new NC::OscProb::NoOscillations;
01169 
01170   for(unsigned int i = 0; i < useParameters.size(); ++i){
01171     if(fSingleShiftedBeam >= 0 && int(i) != fSingleShiftedBeam) continue;
01172 
01173     static NCEventInfo backup; // Suspect that construction is expensive
01174 
01175     backup.DeepCopy(&eventInfo);
01176 
01177     fEventInfo = eventInfo;
01178 
01179     beamInfo.SetSystShifts(useParameters[i], &adjustedValues[i][0]);
01180 
01181     if(FinalEventCheck()){
01182       for(unsigned int j = 0; j < fExtrapolations.size(); ++j){
01183 
01184         // This function applies weight and syst shifts too to the
01185         // object (that it happens to ~ own)
01186         fEventInfo.SetEventWeight(useParameters[i], adjustedValues[i],
01187                                   noosc, 0, runType,
01188                                   true, false);
01189         fEventInfo.reco->weight *= GetMCScaleFactor(det, fileType, beamInfo);
01190         // SetEventWeight will (indirectly) have altered nuEnergy and
01191         // showerEnergy, so make sure they're set right
01192         SetEnergies();
01193         fExtrapolations[j]->AddEvent(eventInfo, useMCAsData, fileType, beamInfo);
01194       }
01195     }
01196 
01197     eventInfo.DeepCopy(&backup);
01198   } // end for i
01199 
01200   delete noosc;
01201 }

void NCExtrapolationModule::ApplySystematicShifts ( NC::RunUtil::ERunType  runType  )  [private]

Apply systematic shifts to fEventInfo appropriate to when it is being used as fake data

Definition at line 716 of file NCExtrapolationModule.cxx.

References fEventInfo, fTrueOscPars, NCEventInfo::reco, NCEventInfo::SetEventWeight(), SystematicsFromRegistry(), and ANtpRecoInfo::weight.

Referenced by SetEventWeight().

00717 {
00718   static bool systematicsToUse[NCType::kNumSystematicParameters];
00719   static vector<double> systematicsAdjust;
00720 
00721   static bool once = true;
00722   if(once){
00723     once = false;
00724     SystematicsFromRegistry(systematicsToUse, systematicsAdjust);
00725   }
00726 
00727   // always use the nue values when finding the event weight because
00728   // the size of the nue contrib is passed in by the macro
00729   fEventInfo.SetEventWeight(systematicsToUse, systematicsAdjust,
00730                             fTrueOscPars, 0, runType, true, true);
00731 
00732   if(TMath::Abs(fEventInfo.reco->weight) < 5.e-2 &&
00733      fEventInfo.reco->weight < 0.)
00734     fEventInfo.reco->weight = 0.;
00735 }

void NCExtrapolationModule::Config ( const Registry r  ) 

Definition at line 431 of file NCExtrapolationModule.cxx.

References NCType::BeamListFromString(), NCPOTCounter::Config(), fBeamIndex, fConfig, fDataMCPath, fExtractionType, fExtrapolationsList, fFileName, fIncludeDataFromLoadedExtrapolations, fLoadExtrapolationsFile, fMakeDQPlotsSpecial, fMockExperimentsSeed, fNumMockExperiments, fOscillationModel, fPIDCustomCut, fPOTCount, fRunsToUse, fSaveExtrapolationsFile, fShiftedBeams, fSimpleShiftedBeams, fSingleShiftedBeam, fSingleSpectrum, fTrueOscPars, fUseMCAsData, fUseMockData, fUsePIDCustomCut, Registry::Get(), gSystem(), and NC::Utility::ParseNumberList().

Referenced by run().

00432 {
00433   fConfig = r;
00434 
00435   int         tmpb;  // a temp bool.
00436   int         tmpi;  // a temp int.
00437   double      tmpd;  // a temp double.
00438   const char* tmps;  // a temp string
00439 
00440   if (r.Get("DataMCPath",            tmps)){
00441     //for some reason the TSystemDirectory constructor can't resolve
00442     //environmental variables, so just take care of it here
00443     TString temp = tmps;
00444     // Assume the form $ENVVAR/path
00445     if(temp.Contains("$")){
00446       int pos = temp.Index("/"); // find the first /
00447       temp.Resize(pos); // and truncate at it
00448       temp.Remove(TString::kLeading, '$'); // drop the $ off the front
00449       fDataMCPath = tmps; // Copy the original string
00450       // and then replace the part that we think is the environment variable
00451       fDataMCPath.Replace(0, pos, gSystem->Getenv(temp));
00452     }
00453     else fDataMCPath = temp;
00454     // Add a trailing slash so that concatenating the path later will work
00455     if(!fDataMCPath.EndsWith("/")) fDataMCPath += "/";
00456   }
00457   if(r.Get("FileName",               tmps)) fFileName           = tmps;
00458 
00459   if(r.Get("OscillationModel",       tmpi)) fOscillationModel   = NCType::EOscModel(tmpi);
00460   if(r.Get("UseMCAsData",            tmpb)) fUseMCAsData        = tmpb;
00461   if(r.Get("ExtractionType",         tmpi)) fExtractionType     = NCType::EExtraction(tmpi);
00462   if(r.Get("SingleSpectrum",         tmpb)) fSingleSpectrum     = tmpb;
00463   if(r.Get("ExtrapolationsList",     tmps)) fExtrapolationsList = tmps;
00464   if(r.Get("UseMockData",            tmpb)) fUseMockData        = tmpb;
00465   if(r.Get("UsePIDCustomCut",        tmpb)) fUsePIDCustomCut    = tmpb;
00466   if(r.Get("PIDCustomCut",           tmpd)) fPIDCustomCut       = tmpd;
00467 
00468   if(r.Get("MakeShiftedBeams",       tmpb)) fShiftedBeams       = tmpb;
00469   if(r.Get("ShiftedBeamsSimpleOnly", tmpb)) fSimpleShiftedBeams = tmpb;
00470   if(r.Get("SingleShiftedBeam",      tmpi)) fSingleShiftedBeam  = tmpi;
00471 
00472   if(r.Get("RunsToUse",              tmps)){
00473     fRunsToUse.clear();
00474     vector<int> runs = NC::Utility::ParseNumberList(tmps);
00475     for(unsigned int n = 0; n < runs.size(); ++n)
00476       fRunsToUse.push_back(NC::RunUtil::ERunType(runs[n]));
00477   }
00478 
00479   if(r.Get("NumMockExperiments",     tmpi)) fNumMockExperiments  = tmpi;
00480   if(r.Get("MockExperimentsSeed",    tmpi)) fMockExperimentsSeed = tmpi;
00481   if(r.Get("LoadExtrapolationsFile", tmps)) fLoadExtrapolationsFile = tmps;
00482   if(r.Get("IncludeDataFromLoadedExtrapolations", tmpb))
00483      fIncludeDataFromLoadedExtrapolations = tmpb;
00484   if(r.Get("SaveExtrapolationsFile", tmps)) fSaveExtrapolationsFile = tmps;
00485 
00486   if(r.Get("MakeDQPlotsSpecial",     tmpb)) fMakeDQPlotsSpecial  = tmpb;
00487 
00488   assert(sizeof(NC::OscProb::OscPars*) == sizeof(int));
00489   if(r.Get("OscPars", tmpi)) fTrueOscPars = (NC::OscProb::OscPars*)(tmpi);
00490 
00491   if (r.Get("BeamType",              tmps))
00492     fBeamIndex = NCType::BeamListFromString(tmps);
00493 
00494   fPOTCount->Config(r, fBeamIndex, fRunsToUse);
00495 }

void NCExtrapolationModule::CreateExtrapolations ( TString  extrapolations  )  [private]

Takes a space separated string of NCExtrapolation code names and adds the relevant objects to fExtrapolations

Definition at line 898 of file NCExtrapolationModule.cxx.

References MuELoss::e, fExtrapolations, fIncludeDataFromLoadedExtrapolations, fLoadExtrapolationsFile, GetExtrapolationFactories(), Msg::kInfo, MSG, and NC::Utility::ParseStringList().

Referenced by Run().

00899 {
00900   MSG("NCExtrapolationModule", Msg::kInfo) << "Registered extrapolations:\n";
00901 
00902   const vector<TString> extrapArgNames = NC::Utility::ParseStringList(extraps);
00903 
00904   for(unsigned int n = 0; n < GetExtrapolationFactories().size(); ++n){
00905     NCExtrapolationFactory* ex = GetExtrapolationFactories()[n];
00906     const TString codeName = ex->GetCodeName();
00907 
00908     MSG("NCExtrapolationModule", Msg::kInfo) << "  " << codeName << " - ";
00909 
00910     bool inExtraps = false;
00911     for(unsigned int i = 0; i < extrapArgNames.size(); ++i)
00912       if(extrapArgNames[i] == codeName) inExtraps = true;
00913 
00914     if(inExtraps){
00915       if(fLoadExtrapolationsFile != ""){
00916         MSG("NCExtrapolationModule", Msg::kInfo) << "Loading from file\n";
00917         TDirectory* curDir = gDirectory;
00918         TFile f(fLoadExtrapolationsFile);
00919         NCExtrapolation* e = (NCExtrapolation*)f.Get("NCExtrapolation"+codeName);
00920         assert(e);
00921         fExtrapolations.push_back(e);
00922         f.Close();
00923         curDir->cd();
00924         // Restoring fd data spectra from the file is not generally
00925         // useful. Want to restore ND data though - it's reading in
00926         // the ND data that takes all the time
00927         if(!fIncludeDataFromLoadedExtrapolations)
00928           e->Reset(false, true, false, false);
00929       }
00930       else{
00931         MSG("NCExtrapolationModule", Msg::kInfo) << "Creating\n";
00932         fExtrapolations.push_back(ex->Create());
00933       } // end if fLoadExtrapolationsFile
00934     }
00935     else{
00936       MSG("NCExtrapolationModule", Msg::kInfo) << "Not creating\n";
00937     } // end if inExtraps
00938   } // end for n
00939 }

TH1 * NCExtrapolationModule::CreateSpecialPlot ( int  k,
TString  type 
) const [private]

Duplicate sufficient logic from NCDataQualityPlot so that fDQNearMCTotalSpecial can be created - breaking circular dependency with DataQuality

Definition at line 75 of file NCExtrapolationModule.cxx.

References kDQVars.

Referenced by NCExtrapolationModule().

00076 {
00077   assert(k >= 3 && k < 6);
00078 
00079   // Definition of a data quality plot: name, title, binning
00080   struct DQDef
00081   {
00082     // Order of elements is important, this is how we are initialised
00083     TString name;
00084     TString title;
00085     int bins;
00086     double start;
00087     double end;
00088   };
00089 
00090   const DQDef kDQVars[6] = {
00091     {"?", "?", -1, -1, -1},
00092     {"?", "?", -1, -1, -1},
00093     {"?", "?", -1, -1, -1},
00094     {"eventLength",    "Event Length (planes)",    50,   0,  500},
00095     {"numTracks",      "Number of Tracks",         10,   0,   10},
00096     {"trackExtension", "Track Extension (planes)", 50, -30,   20}
00097   };
00098 
00099   TH1* ret = new TH1D(kDQVars[k].name+type, "", kDQVars[k].bins, kDQVars[k].start, kDQVars[k].end);
00100 
00101   ret->GetXaxis()->SetTitle(kDQVars[k].title);
00102   ret->GetYaxis()->SetTitle("Events");
00103 
00104   ret->GetXaxis()->CenterTitle();
00105   ret->GetYaxis()->CenterTitle();
00106 
00107   return ret;
00108 }

const Registry & NCExtrapolationModule::DefaultConfig (  )  const

Definition at line 359 of file NCExtrapolationModule.cxx.

References NC::FitMaster::DefaultConfig(), NCExtrapolation::DefaultConfig(), NC::EventAdderDefaultConfig(), Plot::Format(), GetExtrapolationFactories(), NC::RunUtil::kMaxRun, NCType::kNCCCExtractionCuts, NCType::kNumSystematicParameters, NCType::kParams, NCType::kSterileFraction, Registry::LockValues(), Registry::Merge(), NCType::ParamDef::name, Registry::Set(), and Registry::UnLockValues().

Referenced by run().

00360 {
00361   static Registry r;
00362 
00363   r.UnLockValues();
00364 
00365   r.Set("DataMCPath",             "dataFiles/*.root");
00366   r.Set("FarDataPath",            "dataFiles/*.root");
00367   r.Set("FileName",               "extrapolationFile.root");
00368 
00369   r.Set("OscillationModel",       NCType::kSterileFraction);
00370   r.Set("UseMCAsData",            false);
00371   r.Set("SplitMC",                false);
00372   r.Set("SplitMCSeed",            -1);
00373   r.Set("ExtractionType",         NCType::kNCCCExtractionCuts);
00374   r.Set("SingleSpectrum",         false);
00375   r.Set("ExtrapolationsList",     "");
00376   r.Set("BeamType",               "L010z185i");
00377   r.Set("UseMockData",            false);
00378   r.Set("MockDataSet",            "F21910001");
00379 
00380   TString runsToUse;
00381   for(int n = 0; n <= NC::RunUtil::kMaxRun; ++n)
00382     runsToUse += TString::Format("%d ", n);
00383   r.Set("RunsToUse",              runsToUse);
00384 
00385   r.Set("OscPars",                0);
00386   r.Set("NumMockExperiments",     0);
00387   r.Set("MockExperimentsSeed",    0);
00388   r.Set("LoadExtrapolationsFile", "");
00389   r.Set("IncludeDataFromLoadedExtrapolations", false);
00390   r.Set("SaveExtrapolationsFile", "");
00391 
00392   r.Set("MakeDQPlotsSpecial",     false);
00393 
00394   // Get the default configurations for all the registered extrapolations
00395   vector<NCExtrapolationFactory*> facts =  GetExtrapolationFactories();
00396   for(unsigned int n = 0; n < facts.size(); ++n)
00397     r.Merge(facts[n]->DefaultConfig());
00398 
00399   //PID sensitivity study
00400   r.Set("UsePIDCustomCut",        false);
00401   r.Set("PIDCustomCut",           0.0);
00402 
00403   r.Set("MakeShiftedBeams",       false);
00404   r.Set("ShiftedBeamsSimpleOnly", false);
00405   r.Set("SingleShiftedBeam",      -1);
00406 
00407   //set the defaults for the systematic parameters
00408   //set them all off for fitting and changing mc by default
00409   TString adjust   = "Adjust";
00410   TString mcAsData = "ChangeMCAsData";
00411   TString fit      = "Fit";
00412   for(int i = 0; i < NCType::kNumSystematicParameters; ++i){
00413     r.Set(NCType::kParams[i].name,            false);
00414     r.Set(mcAsData + NCType::kParams[i].name, false);
00415     r.Set(adjust + NCType::kParams[i].name,   0); // measured in sigma
00416     r.Set(fit + NCType::kParams[i].name,      false);
00417   }
00418 
00419   // Add all the configuration that NCExtrapolation knows how to read
00420   r.Merge(NCExtrapolation::DefaultConfig());
00421 
00422   r.Merge(NC::FitMaster::DefaultConfig());
00423 
00424   r.Merge(NC::EventAdderDefaultConfig());
00425 
00426   r.LockValues();
00427   return r;
00428 }

void NCExtrapolationModule::DoMockExperiments (  )  [private]

Definition at line 614 of file NCExtrapolationModule.cxx.

References NCEventInfo::beam, ANtpBeamInfo::beamType, fConfig, fEventInfo, fExtrapolations, fFDMCSample, fMockExperimentsSeed, fMockFits, fNumMockExperiments, fTrueOscPars, NC::FitMaster::GetBestFitPointAsRegistry(), NCType::kBeamFile, NC::RunUtil::kRunI, Msg::kWarning, MSG, NC::FitMaster::Prepare(), reg, NC::FitMaster::Run(), Registry::Set(), and NC::FitMaster::SetFixedValuesForMarginalization().

Referenced by Run().

00615 {
00616   if(fMockExperimentsSeed == 0)
00617     MSG("NCExtrapolationModule", Msg::kWarning) << "DoMockExperiments: random seed not set, using default (0)" << endl;
00618 
00619 
00620   TRandom3 r;
00621 
00622   for(int n = 0; n < fNumMockExperiments; ++n){
00623     // Reset everyone's FD data
00624     for(unsigned int i = 0; i < fExtrapolations.size(); ++i)
00625       fExtrapolations[i]->Reset(false, true, false, false);
00626 
00627     r.SetSeed(fMockExperimentsSeed);
00628     r.SetSeed(n+r.Integer(UInt_t(-1)));
00629 
00630     for(unsigned int n = 0; n < fFDMCSample.size(); ++n){
00631       NCEventInfo* s = fFDMCSample[n];
00632       for(unsigned int i = 0; i < fExtrapolations.size(); ++i){
00633         double tmp_weight = s->reco->weight;
00634         s->reco->weight = r.Poisson(s->reco->weight);
00635         // Is this way faster?
00636         //      s->reco->weight = (s->reco->weight > r.Uniform()) ? 1 : 0;
00637 
00638         BeamType::BeamType_t beamType = (BeamType::BeamType_t)(fEventInfo.beam->beamType);
00639         NCBeam::Info beamInfo(beamType, NC::RunUtil::kRunI);
00640 
00641         if(s->reco->weight){
00642           fExtrapolations[i]->AddEvent(*s, true,
00643                                        NCType::kBeamFile, // TODO is kBeamFile right?
00644                                        beamInfo);
00645         }
00646         s->reco->weight = tmp_weight;
00647       }//end loop over extrapolation objects
00648     }
00649 
00650     for(unsigned int i = 0; i < fExtrapolations.size(); ++i){
00651       NCExtrapolation* extrap = fExtrapolations[i];
00652       //      extrap->CombineRuns(Detector::kFar);
00653       NC::FitMaster fm(extrap);
00654       Registry r = fConfig;
00655       // Counteract the "preciseParams" scaling normally done in the
00656       // initial fit. This is a bit ugly, would be better to disable the
00657       // scaling instead of fighting it.
00658 
00659       // Changed my mind, we need to be fair to the real fit
00660 
00661       //      r.UnLockValues();
00662       //      r.Set("PrecScale", 0.01);
00663 
00664       fm.Prepare(r);
00665 
00666       fm.SetFixedValuesForMarginalization(fTrueOscPars);
00667       fm.Run(0);
00668 
00669       const double trueChi = extrap->FindChiSqrForPars(fTrueOscPars,
00670                                                        NC::SystPars());
00671 
00672       // Slight problem here in that we don't distinguish which extrapolation
00673       // this result came from, so there's no way to tell in the output file.
00674       // Isn't a problem if you only run one extrapolation, which is the common
00675       // use case.
00676       Registry* reg = fm.GetBestFitPointAsRegistry();
00677       reg->Set("true_chisq", trueChi);
00678       fMockFits.push_back(reg);
00679     }
00680   }
00681 }

void NCExtrapolationModule::DrawDataQualityPlots (  )  [private]

Definition at line 143 of file NCExtrapolationModule.cxx.

References DrawDataQualityPlotsSpecial(), and fMakeDQPlotsSpecial.

Referenced by Run().

00144 {
00145   // get a pointer to the current directory
00146   // this is one of the output files
00147   TDirectory* saveDir = gDirectory;
00148 
00149   //loop over the data quality histograms
00150   //make folders for data/mc and subfolders for near/far
00151   TDirectory* dir = saveDir->mkdir("DataQuality", "DataQuality");
00152   dir->cd();
00153 
00154   TDirectory* near = dir->mkdir("NearDetector", "NearDetector");
00155 
00156   near->cd();
00157 
00158   if(fMakeDQPlotsSpecial) DrawDataQualityPlotsSpecial();
00159 
00160   saveDir->cd();
00161 }

void NCExtrapolationModule::DrawDataQualityPlotsSpecial (  )  [private]

Definition at line 164 of file NCExtrapolationModule.cxx.

References fDQNearMCTotalSpecial.

Referenced by DrawDataQualityPlots().

00165 {
00166   for(int dist = 0; dist < 3; ++dist){
00167 
00168     fDQNearMCTotalSpecial[dist]->Write();
00169 
00170 
00171     TString canvName = fDQNearMCTotalSpecial[dist]->GetName();
00172     //    int index = canvName.Index("MC");
00173     canvName += "Canv";
00174     TCanvas *canv = new TCanvas(canvName, canvName, 150, 10, 900, 600);
00175     TLegend *leg = new TLegend(0.75, 0.75, 0.95, 0.95);
00176     leg->SetBorderSize(0);
00177 
00178     fDQNearMCTotalSpecial[dist]->Draw("");
00179     leg->AddEntry(fDQNearMCTotalSpecial[dist], "MC Total", "l");
00180     leg->Draw();
00181 
00182     gDirectory->Append(canv);
00183 
00184   }//end loop over dists
00185 }

void NCExtrapolationModule::ExtrapolateNearToFar (  )  [private]

Add the FD events to the extrapolations and run the fit for each one.

Definition at line 583 of file NCExtrapolationModule.cxx.

References fConfig, fExtrapolations, fFitMasters, fTrueOscPars, Msg::kInfo, MSG, NC::FitMaster::Prepare(), and NC::FitMaster::Run().

Referenced by Run().

00584 {
00585   /*
00586   const bool loadingExtrapolations = fLoadExtrapolationsFile != "";
00587 
00588   // Ugh - should instead break this function down so we can select parts of it
00589   if(fLoadExtrapolationsFile != ""){
00590     for(unsigned int i = 0; i < fExtrapolations.size(); ++i){
00591       NC::FitMaster* fm = new NC::FitMaster(fExtrapolations[i]);
00592       fm->Prepare(fConfig);
00593       fm->Run(fTrueOscPars);
00594       fFitMasters.push_back(fm);
00595     }
00596     return;
00597   }
00598   */
00599 
00600   MSG("NCExtrapolationModule", Msg::kInfo) << "ExtrapolateNearToFar" << endl;
00601 
00602   //predict the far detector and make sure to combine any running conditions
00603   for(unsigned int i = 0; i < fExtrapolations.size(); ++i){
00604     fExtrapolations[i]->DoneFilling();
00605     NC::FitMaster* fm = new NC::FitMaster(fExtrapolations[i]);
00606     fm->Prepare(fConfig);
00607     fm->Run(fTrueOscPars);
00608     fFitMasters.push_back(fm);
00609   }
00610 }

void NCExtrapolationModule::FillDataQualityPlotsSpecial ( std::vector< TH1 * > &  dq,
bool  osc 
) [private]

Definition at line 531 of file NCExtrapolationModule.cxx.

References ANtpHeaderInfo::detector, ANtpRecoInfo::eventLength, fEventInfo, NCEventInfo::header, ANtpRecoInfo::inFiducialVolume, ANtpRecoInfo::isSimpleCutsClean, kDQEventLength, kDQNumTracks, kDQTrackExtension, Detector::kNear, ANtpRecoInfo::numberTracks, NCEventInfo::reco, ANtpRecoInfo::showerEnergyNC, ANtpRecoInfo::trackExtension, and ANtpRecoInfo::weight.

Referenced by AddEventToExtrapolations().

00532 {
00533 
00534   osc=false;
00535 
00536   //dont bother with events outside the fiducial volume
00537   if(fEventInfo.reco->inFiducialVolume < 1) return;
00538 
00539   double weight=fEventInfo.reco->weight;
00540   
00541   double trackExtension = -1.*fEventInfo.reco->trackExtension;
00542   double showerEnergy = fEventInfo.reco->showerEnergyNC;
00543 
00544   if(fEventInfo.header->detector == int(Detector::kNear)
00545      && fEventInfo.reco->isSimpleCutsClean< 1 ) return;
00546 
00547   dq[kDQEventLength-3]->Fill(fEventInfo.reco->eventLength, weight);
00548   dq[kDQNumTracks-3]->Fill(fEventInfo.reco->numberTracks, weight);
00549 
00550   if(fEventInfo.reco->numberTracks > 0
00551      && fEventInfo.reco->trackExtension > -9000.
00552      && showerEnergy > 0.0)
00553     dq[kDQTrackExtension-3]->Fill(trackExtension, weight);
00554 
00555 
00556   //  cout << "Weight: " << weight << endl
00557   //    << "eventLength: " << fEventInfo.reco->eventLength
00558   //    << " histo: " << dq[0]->GetBinContent(15) << endl
00559   //    << "NumTracks: " << fEventInfo.reco->numberTracks
00560   //    << " histo: " << dq[1]->GetBinContent(2) << endl
00561   //       << "TrackExtension: " << trackExtension  << "  " << showerEnergy
00562   //    << " histo: " << dq[2]->GetBinContent(30) << endl
00563   //    << endl;
00564 }

bool NCExtrapolationModule::FinalEventCheck (  )  [private]

any last checks.

Definition at line 887 of file NCExtrapolationModule.cxx.

References fEventInfo, NCEventInfo::FinalEventCheck(), fSingleSpectrum, NCEventInfo::header, and ANtpHeaderInfo::isGoodData.

Referenced by AddEventToExtrapolations(), and AddShiftedEventToExtrapolations().

00888 {
00889   //check any final cuts here
00890   if(!fEventInfo.FinalEventCheck()
00891      && !fSingleSpectrum) return false;
00892 
00893   return fEventInfo.header->isGoodData;
00894 }

std::vector< NCExtrapolationFactory * > & NCExtrapolationModule::GetExtrapolationFactories (  )  [static, private]

The various extrapolations that have registered themselves.

Definition at line 1206 of file NCExtrapolationModule.cxx.

Referenced by AddExtrapolation(), CreateExtrapolations(), and DefaultConfig().

01207 {
01208   // Looks like we were falling foul of some variant of the
01209   // "static initialization order fiasco". Apply the workaround from
01210   // http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.13
01211   static std::vector<NCExtrapolationFactory*> facts;
01212   return facts;
01213 }

void NCExtrapolationModule::GetListOfShifts ( std::vector< bool * > &  useParameters,
std::vector< std::vector< double > > &  adjustedValues 
) const [private]

Return descriptions for all the different combinations of systematically shifted beam required by AddShiftedEventToExtrapolations

Referenced by AddShiftedEventToExtrapolations().

double NCExtrapolationModule::GetMCScaleFactor ( Detector::Detector_t  det,
NCType::EFileType  fileType,
NCBeam::Info  info 
) [private]

Get the factor to scale the MC by to match the data. Will be zero for beams which have no data.

The rationale for the default value is to allow a check (in AddEventToExtrapolations) to ensure that the MC beams that have events added to them are the ones that were selected in the RunsToUse registry key *and* have data available

Definition at line 776 of file NCExtrapolationModule.cxx.

References fDataPOTFar, fDataPOTNear, fMCPOTFar, fMCPOTFarElectron, fMCPOTFarTau, fMCPOTNear, GetScaleFactorFromMaps(), NCType::kElectronFile, Detector::kFar, Detector::kNear, NCType::kTauFile, and NCBeam::Info::SetSystShifts().

Referenced by AddShiftedEventToExtrapolations(), and SetEventWeight().

00779 {
00780   // Choose the appropriate pot maps for this event and scale
00781   // down the event to match the data POT.
00782   POTMap* potData=0;
00783   POTMap* potMC=0;
00784   switch(det){
00785   case Detector::kNear:
00786     potData=&fDataPOTNear;
00787     potMC=&fMCPOTNear;
00788     break;
00789   case Detector::kFar:
00790     potData=&fDataPOTFar;
00791     switch(fileType){
00792     case NCType::kTauFile:
00793       potMC=&fMCPOTFarTau;
00794       break;
00795     case NCType::kElectronFile:
00796       potMC=&fMCPOTFarElectron;
00797       break;
00798     default:
00799       potMC=&fMCPOTFar;
00800     }
00801     break;
00802   default:
00803     assert(0 && "Unknown detector. This shouldn't happen");
00804   }
00805 
00806   double tmp=GetScaleFactorFromMaps(*potData, *potMC, info);
00807   if(tmp>0) return tmp;
00808 
00809   // ...otherwise try to find the same beam with no syst shifts
00810   const vector<NCType::EFitParam> adj;
00811   const vector<double> vals;
00812   info.SetSystShifts(adj, vals);
00813 
00814   return GetScaleFactorFromMaps(*potData, *potMC, info);
00815 }

double NCExtrapolationModule::GetScaleFactorFromMaps ( POTMap potData,
POTMap potMC,
NCBeam::Info  info 
) [private]

Helper for GetMCScaleFactor.

Gets the MC scale factor for beam info from the maps potData and potMC. Tries the nominal (no systematics) beam if not found, and asserts if there is data for this beam but no MC

Definition at line 818 of file NCExtrapolationModule.cxx.

References Msg::kError, and MSG.

Referenced by GetMCScaleFactor().

00821 {
00822   // See if we actually found the beam in both...
00823   const bool foundData = potData.find(info) != potData.end();
00824   const bool foundMC = potMC.find(info) != potMC.end();
00825 
00826   // If we have data POTs for this beam, we'd better have some MC to go with it.
00827   if(foundData && !foundMC){
00828     MSG("NCExtrapolationModule", Msg::kError)
00829       << "Found data POT but not MC for " 
00830       << info << endl;
00831     
00832     MSG("NCExtrapolationModule", Msg::kError) << "Data POTs: " << endl;
00833     for(POTMap::iterator it=potData.begin(); it!=potData.end(); ++it)
00834       MSG("NCExtrapolationModule", Msg::kError)
00835         << it->first << ": " << it->second << endl;
00836     
00837     MSG("NCExtrapolationModule", Msg::kError) << "MC POTs: " << endl;
00838     for(POTMap::iterator it=potMC.begin(); it!=potMC.end(); ++it)
00839       MSG("NCExtrapolationModule", Msg::kError)
00840         << it->first << ": " << it->second << endl;
00841     exit(1);
00842   }
00843 
00844   // If we have no data, return 0;
00845   if(!foundData) return 0;
00846 
00847   // Otherwise return the actual scale factor
00848   return potData.find(info)->second/potMC.find(info)->second;
00849 }

void NCExtrapolationModule::PrepareForExtrapolation (  )  [private]

Prepare all extrapolation objects by passing the config Registry to them and adding the near detector events from the chains passed

Definition at line 568 of file NCExtrapolationModule.cxx.

References fConfig, fExtrapolations, Msg::kInfo, and MSG.

Referenced by Run().

00569 {
00570   MSG("NCExtrapolationModule", Msg::kInfo) << "PrepareForExtrapolation" << endl;
00571   //pass the module registry into the extrapolations to prepare them
00572   for(unsigned int i = 0; i < fExtrapolations.size(); ++i)
00573     fExtrapolations[i]->Prepare(fConfig);
00574 }

void NCExtrapolationModule::Run (  ) 

Definition at line 188 of file NCExtrapolationModule.cxx.

References NC::IEventAdder::AddEvents(), AddFilesToChain(), CreateExtrapolations(), DoMockExperiments(), DrawDataQualityPlots(), NC::EventAdderBuilder(), ExtrapolateNearToFar(), fBeamIndex, fConfig, fDataPOTFar, fDataPOTNear, fEventInfo, fExtractionType, fExtrapolations, fExtrapolationsList, fFileName, fFitMasters, fMCPOTFar, fMCPOTFarElectron, fMCPOTFarTau, fMCPOTNear, fMockFits, fNumMockExperiments, Plot::Format(), fPOTCount, fRunsToUse, fSaveExtrapolationsFile, fTrueOscPars, fUseMCAsData, fUseMockData, NCType::kBeamFile, NCType::kData, NCType::kElectronFile, NCType::kExtractionNames, Detector::kFar, Msg::kInfo, NCType::kMC, NCType::kMockFile, Detector::kNear, NCType::kTauFile, MSG, PrepareForExtrapolation(), Registry::Print(), runPeriod, NCEventInfo::SetChainBranches(), and NCPOTCounter::SetPOTValues().

Referenced by run().

00189 {
00190   fConfig.Print(); // Print out the configuration in use.
00191 
00192   assert(fTrueOscPars);
00193 
00194   //get the pot for the different beams
00195   const NCType::EFileType fileType = fUseMockData ? NCType::kMockFile : NCType::kBeamFile;
00196 
00197   //use following map for FD MC
00198   fPOTCount->SetPOTValues(fDataPOTNear,          Detector::kNear,
00199                           NCType::kBeamFile,     NCType::kData);
00200 
00201   fPOTCount->SetPOTValues(fMCPOTNear,            Detector::kNear,
00202                           NCType::kBeamFile,     NCType::kMC);
00203 
00204   fPOTCount->SetPOTValues(fDataPOTFar,           Detector::kFar,
00205                           fileType,              NCType::kData);
00206 
00207   fPOTCount->SetPOTValues(fMCPOTFar,             Detector::kFar,
00208                           NCType::kBeamFile,     NCType::kMC);
00209 
00210   fPOTCount->SetPOTValues(fMCPOTFarTau,          Detector::kFar,
00211                           NCType::kTauFile,      NCType::kMC);
00212 
00213   fPOTCount->SetPOTValues(fMCPOTFarElectron,     Detector::kFar,
00214                           NCType::kElectronFile, NCType::kMC);
00215 
00216   MSG("NCExtrapolationModule", Msg::kInfo) << "Done setting POT values" << endl;
00217 
00218 
00219   ChainMap dataND;
00220   ChainMap mcND;
00221   ChainMap dataFD;
00222   ChainMap mcFD;
00223   ChainMap mcTauFD;
00224   ChainMap mcElectronFD;
00225 
00226   // The beamtype/runperiod pairs we're using
00227   vector<NCBeam::Info> infos;
00228 
00229   for(unsigned int bidx = 0; bidx < fBeamIndex.size(); ++bidx){
00230     const BeamType::BeamType_t bt = fBeamIndex[bidx];
00231     for(unsigned int runPidx=0; runPidx < fRunsToUse.size(); ++runPidx){
00232       const NC::RunUtil::ERunType runPeriod = fRunsToUse[runPidx];
00233       const NCBeam::Info info(bt, runPeriod);
00234 
00235       infos.push_back(info);
00236     }
00237   }
00238 
00239   for(unsigned int i=0; i<infos.size(); ++i){
00240     NCBeam::Info info=infos[i];
00241     dataND[info] = new TChain("uDST");
00242     mcND[info] = new TChain("uDST");
00243     dataFD[info] = new TChain("uDST");
00244     mcFD[info] = new TChain("uDST");
00245     mcTauFD[info] = new TChain("uDST");
00246     mcElectronFD[info] = new TChain("uDST");
00247   }
00248 
00249   AddFilesToChain(dataND,  Detector::kNear, NCType::kBeamFile, NCType::kData);
00250   AddFilesToChain(mcND,    Detector::kNear, NCType::kBeamFile, NCType::kMC);
00251   AddFilesToChain(dataFD,  Detector::kFar,  fileType,          NCType::kData);
00252   AddFilesToChain(mcFD,    Detector::kFar,  NCType::kBeamFile, NCType::kMC);
00253   AddFilesToChain(mcTauFD, Detector::kFar,  NCType::kTauFile,  NCType::kMC);
00254   AddFilesToChain(mcElectronFD, Detector::kFar, NCType::kElectronFile, NCType::kMC);
00255 
00256   const TString ext = NCType::kExtractionNames[fExtractionType];
00257 
00258   for(unsigned int i=0; i<infos.size(); ++i){
00259     NCBeam::Info info=infos[i];
00260     fEventInfo.SetChainBranches(dataND[info],       ext, fUseMCAsData);
00261     fEventInfo.SetChainBranches(dataFD[info],       ext, fUseMCAsData);
00262     fEventInfo.SetChainBranches(mcND[info],         ext, true);
00263     fEventInfo.SetChainBranches(mcFD[info],         ext, true);
00264     fEventInfo.SetChainBranches(mcTauFD[info],      ext, true);
00265     fEventInfo.SetChainBranches(mcElectronFD[info], ext, true);
00266   } 
00267 
00268 
00269   CreateExtrapolations(fExtrapolationsList);
00270 
00271   PrepareForExtrapolation();
00272 
00273   NC::IEventAdder* eventAdder = NC::EventAdderBuilder(fConfig);
00274 
00275   for(unsigned int i=0; i<infos.size(); ++i){
00276     NCBeam::Info info=infos[i];
00277     eventAdder->AddEvents(this, &fEventInfo,
00278                           dataND[info], mcND[info],
00279                           dataFD[info], mcFD[info], mcTauFD[info], mcElectronFD[info]);
00280   }
00281   delete eventAdder;
00282 
00283   ExtrapolateNearToFar();
00284 
00285   if(fNumMockExperiments > 0) DoMockExperiments();
00286 
00287   //make a file and the trees to go into the file
00288 
00289   MSG("NCExtrapolationModule", Msg::kInfo) << "fFileName = " << fFileName << endl;
00290 
00291   TFile ntpFile(fFileName, "RECREATE");
00292   ntpFile.cd();
00293 
00294   for(unsigned int k = 0; k < fExtrapolations.size(); ++k){
00295     TDirectory* saveDir = gDirectory;
00296     TString plotName = "plots"+fExtrapolations[k]->GetShortName();
00297     TDirectory* newDir = gDirectory->mkdir(plotName, plotName);
00298 
00299     // In case we failed to make the new directory then this way
00300     // probably gives us the best chance of rescuing the plots
00301     if(newDir) newDir->cd();
00302     fFitMasters[k]->WriteResources();
00303     if(newDir) newDir->cd();
00304     fExtrapolations[k]->WriteResources(fTrueOscPars);
00305 
00306     saveDir->cd();
00307   }
00308 
00309   if(!fUseMCAsData && !fUseMockData) DrawDataQualityPlots();
00310 
00311   ntpFile.cd();
00312   fConfig.SetName("config_registry");
00313   fConfig.Write();
00314 
00315   if(!fMockFits.empty()){
00316     ntpFile.cd();
00317     gDirectory->mkdir("mock_expts")->cd();
00318     for(unsigned int n = 0; n < fMockFits.size(); ++n){
00319       Registry* r = fMockFits[n];
00320       r->SetName(TString::Format("expt_%d", n));
00321       r->Write();
00322     }
00323     ntpFile.cd();
00324   }
00325 
00326   MSG("NCExtrapolationModule", Msg::kInfo) << "Writing Final File!" << endl;
00327 
00328   ntpFile.Write();
00329   ntpFile.Close();
00330 
00331   if(fSaveExtrapolationsFile != ""){
00332     TFile saveFile(fSaveExtrapolationsFile, "RECREATE");
00333     for(unsigned int k = 0; k < fExtrapolations.size(); ++k)
00334       fExtrapolations[k]->Write();
00335     saveFile.Close();
00336   }
00337 }

void NCExtrapolationModule::SetEnergies (  )  [private]

Set reco.nuEnergy and reco.showerEnergy to the appropriate NC or CC variant.

Definition at line 738 of file NCExtrapolationModule.cxx.

References NCEventInfo::analysis, fEventInfo, ANtpAnalysisInfo::isCC, ANtpAnalysisInfo::isNC, ANtpRecoInfo::nuEnergy, ANtpRecoInfo::nuEnergyCC, ANtpRecoInfo::nuEnergyNC, NCEventInfo::reco, NCEventInfo::reco_nom, ANtpRecoInfo::showerEnergy, ANtpRecoInfo::showerEnergyCC, and ANtpRecoInfo::showerEnergyNC.

Referenced by AddEventToExtrapolations(), AddShiftedEventToExtrapolations(), and SetEventWeight().

00739 {
00740   if(fEventInfo.analysis->isCC > 0){
00741     // The RHSs here *should* be reco and not reco_nom, because we
00742     // want the shifted value of (nu|shower)EnergyCC if it has been
00743     // shifted
00744     fEventInfo.reco->nuEnergy = fEventInfo.reco->nuEnergyCC;
00745     fEventInfo.reco->showerEnergy = fEventInfo.reco->showerEnergyCC;
00746 
00747     // We need to do this because (inter alia) the calculation of the
00748     // ND cleaning syst relies on showerEnergy being set to the right
00749     // one. We're safe from considerations of whether things have been
00750     // systematically shifted because reco_nom is never systematically
00751     // shifted
00752     fEventInfo.reco_nom->nuEnergy = fEventInfo.reco_nom->nuEnergyCC;
00753     fEventInfo.reco_nom->showerEnergy = fEventInfo.reco_nom->showerEnergyCC;
00754   }
00755   else if(fEventInfo.analysis->isNC > 0){
00756     fEventInfo.reco->nuEnergy = fEventInfo.reco->showerEnergyNC;
00757     fEventInfo.reco->showerEnergy = fEventInfo.reco->showerEnergyNC;
00758 
00759     // See comment above
00760     fEventInfo.reco_nom->nuEnergy = fEventInfo.reco_nom->nuEnergyNC;
00761     fEventInfo.reco_nom->showerEnergy = fEventInfo.reco_nom->showerEnergyNC;
00762 
00763     // (PAR) This used to be set here, but that breaks FindEventWeight
00764     // for NC events if we're using CC energy for those. But
00765     // NCExtrapolation::DrawBestFitSpectra relies on (shower+track)
00766     // giving the NC or CC energy appropriate to the classification,
00767     // so setting track energy to zero is now done in NCEnergyBin::AddEventToBin
00768     //fEventInfo.reco->muEnergy = 0.;
00769   }
00770 
00771   // Energies < 0 occur when there's no shower and we get a default value
00772   if(fEventInfo.reco->showerEnergy < 0.) fEventInfo.reco->showerEnergy = 0.;
00773 }

void NCExtrapolationModule::SetEventWeight ( BeamType::BeamType_t  beamType,
NC::RunUtil::ERunType  runType,
bool  fakeDataSet 
) [private]

Set the event weight appropriately for its type and run, including scaling MC to match the data POTs. If fakeDataSet is true, also apply systematic shifts and rescaling appropriate to fake data

Definition at line 852 of file NCExtrapolationModule.cxx.

References ApplySystematicShifts(), ANtpHeaderInfo::dataType, det, ANtpHeaderInfo::detector, fEventInfo, NCType::FindFileType(), GetMCScaleFactor(), NCEventInfo::GetSKZPWeight(), NCEventInfo::header, SimFlag::kData, SimFlag::kMC, NCEventInfo::reco, SetEnergies(), and ANtpRecoInfo::weight.

Referenced by AddEventToExtrapolations().

00855 {
00856   Detector::Detector_t det = Detector::Detector_t(fEventInfo.header->detector);
00857   SimFlag::SimFlag_t sim = SimFlag::SimFlag_t(fEventInfo.header->dataType);
00858   NCType::EFileType fileType = NCType::FindFileType(fEventInfo.header);
00859 
00860   // Data events don't get scaled or systematically shifted
00861   if(sim==SimFlag::kData){
00862     SetEnergies();
00863     return;
00864   }
00865   else if(sim==SimFlag::kMC){
00866     if(fakeDataSet){
00867       // This includes SKZP via NCEventInfo::GetEventWeight
00868       ApplySystematicShifts(runType);
00869     }
00870     else{
00871       // Just apply the SKZP weight
00872       fEventInfo.reco->weight=fEventInfo.GetSKZPWeight();
00873     }
00874 
00875     const NCBeam::Info info=NCBeam::Info(beamType, runType);
00876     fEventInfo.reco->weight *= GetMCScaleFactor(det, fileType, info);
00877     // ApplySystematicShifts will (indirectly) have altered nuEnergy and
00878     // showerEnergy, so make sure they're set right
00879     SetEnergies();
00880   }
00881   else{
00882     assert(0 && "This shouldn't happen");
00883   }
00884 }

void NCExtrapolationModule::SetMCExposureForBeam ( NCBeam::Info  beam,
double  pot 
)

Definition at line 353 of file NCExtrapolationModule.cxx.

References fPOTCount, and NCPOTCounter::SetMCExposureForBeam().

Referenced by set_mc_exposure_for_beam().

00354 {
00355   fPOTCount->SetMCExposureForBeam(beam, pot);
00356 }

void NCExtrapolationModule::SystematicsFromRegistry ( bool *  systematicsToUse,
std::vector< double > &  systematicsAdjust 
) [private]

Referenced by ApplySystematicShifts().


Member Data Documentation

std::vector<BeamType::BeamType_t> NCExtrapolationModule::fBeamIndex [private]

index of beams to use

Definition at line 187 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

Registry NCExtrapolationModule::fConfig [private]

Definition at line 246 of file NCExtrapolationModule.h.

Referenced by Config(), DoMockExperiments(), ExtrapolateNearToFar(), PrepareForExtrapolation(), and Run().

TString NCExtrapolationModule::fDataMCPath [private]

path to uDST for data and MC files

Definition at line 180 of file NCExtrapolationModule.h.

Referenced by AddFilesToChain(), and Config().

POTMap NCExtrapolationModule::fDataPOTFar [private]

Definition at line 231 of file NCExtrapolationModule.h.

Referenced by GetMCScaleFactor(), and Run().

POTMap NCExtrapolationModule::fDataPOTNear [private]

Definition at line 230 of file NCExtrapolationModule.h.

Referenced by GetMCScaleFactor(), and Run().

std::vector<TH1*> NCExtrapolationModule::fDQNearMCTotalSpecial [private]

Definition at line 178 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), DrawDataQualityPlotsSpecial(), and NCExtrapolationModule().

NCEventInfo NCExtrapolationModule::fEventInfo [private]

Definition at line 208 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), AddShiftedEventToExtrapolations(), ApplySystematicShifts(), DoMockExperiments(), FillDataQualityPlotsSpecial(), FinalEventCheck(), NCExtrapolationModule(), Run(), SetEnergies(), SetEventWeight(), and ~NCExtrapolationModule().

NCType::EExtraction NCExtrapolationModule::fExtractionType [private]

the extraction to use

Definition at line 185 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

std::vector<NCExtrapolation*> NCExtrapolationModule::fExtrapolations [private]

Definition at line 213 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), AddShiftedEventToExtrapolations(), CreateExtrapolations(), DoMockExperiments(), ExtrapolateNearToFar(), PrepareForExtrapolation(), Run(), and ~NCExtrapolationModule().

TString NCExtrapolationModule::fExtrapolationsList [private]

A space-separated list of extrapolations to use, from job macro.

Definition at line 216 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

std::vector<NCEventInfo*> NCExtrapolationModule::fFDMCSample [private]

Definition at line 240 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), DoMockExperiments(), and ~NCExtrapolationModule().

TString NCExtrapolationModule::fFileName [private]

name of output file

Definition at line 181 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

std::vector<NC::FitMaster*> NCExtrapolationModule::fFitMasters [private]

Definition at line 214 of file NCExtrapolationModule.h.

Referenced by ExtrapolateNearToFar(), Run(), and ~NCExtrapolationModule().

bool NCExtrapolationModule::fIncludeDataFromLoadedExtrapolations [private]

If fLoadExtrapolationsFile then load data part of spectrum too.

Definition at line 221 of file NCExtrapolationModule.h.

Referenced by Config(), and CreateExtrapolations().

TString NCExtrapolationModule::fLoadExtrapolationsFile [private]

Filename to load extrapolation objects from. Empty string -> no loading.

Definition at line 219 of file NCExtrapolationModule.h.

Referenced by Config(), and CreateExtrapolations().

bool NCExtrapolationModule::fMakeDQPlotsSpecial [private]

Ask Alex...

Definition at line 206 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), Config(), and DrawDataQualityPlots().

POTMap NCExtrapolationModule::fMCPOTFar [private]

Definition at line 233 of file NCExtrapolationModule.h.

Referenced by GetMCScaleFactor(), and Run().

POTMap NCExtrapolationModule::fMCPOTFarElectron [private]

Definition at line 235 of file NCExtrapolationModule.h.

Referenced by GetMCScaleFactor(), and Run().

POTMap NCExtrapolationModule::fMCPOTFarTau [private]

Definition at line 234 of file NCExtrapolationModule.h.

Referenced by GetMCScaleFactor(), and Run().

POTMap NCExtrapolationModule::fMCPOTNear [private]

Definition at line 232 of file NCExtrapolationModule.h.

Referenced by GetMCScaleFactor(), and Run().

int NCExtrapolationModule::fMockExperimentsSeed [private]

Definition at line 239 of file NCExtrapolationModule.h.

Referenced by Config(), and DoMockExperiments().

std::vector<Registry*> NCExtrapolationModule::fMockFits [private]

Definition at line 244 of file NCExtrapolationModule.h.

Referenced by DoMockExperiments(), Run(), and ~NCExtrapolationModule().

int NCExtrapolationModule::fNumMockExperiments [private]

Zero if fake experiments are not to be carried out (default).

Definition at line 238 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), Config(), DoMockExperiments(), and Run().

NCType::EOscModel NCExtrapolationModule::fOscillationModel [private]

model to use in the fit

Definition at line 184 of file NCExtrapolationModule.h.

Referenced by Config().

double NCExtrapolationModule::fPIDCustomCut [private]

Custom cut value.

Definition at line 190 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), and Config().

NCPOTCounter* NCExtrapolationModule::fPOTCount [private]

Definition at line 242 of file NCExtrapolationModule.h.

Referenced by AddFilesToChain(), Config(), NCExtrapolationModule(), Run(), SetMCExposureForBeam(), and ~NCExtrapolationModule().

std::vector<NC::RunUtil::ERunType> NCExtrapolationModule::fRunsToUse [private]

define which runs to use

Definition at line 227 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

TString NCExtrapolationModule::fSaveExtrapolationsFile [private]

Filename to save extrapolation objects to. Empty string -> no saving.

Definition at line 223 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

bool NCExtrapolationModule::fShiftedBeams [private]

If set then AddShiftedEventToExtrapolations is called.

Definition at line 193 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), and Config().

bool NCExtrapolationModule::fSimpleShiftedBeams [private]

Controls whether to generate a simpler set of shifted beams.

If not set then $ 3^n $ shifted beams are created. If set then only $ 2^n+1 $ beams are created

Definition at line 198 of file NCExtrapolationModule.h.

Referenced by Config().

int NCExtrapolationModule::fSingleShiftedBeam [private]

Controls if only a single shifted beam is made.

If set to -1 then no effect. If set then only the shifted beam from GetListOfShifts with this index is created. This is useful for generating a large number of beams in parallel as multiple jobs.

Definition at line 204 of file NCExtrapolationModule.h.

Referenced by AddShiftedEventToExtrapolations(), and Config().

bool NCExtrapolationModule::fSingleSpectrum [private]

use a single spectrum

Definition at line 225 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), Config(), and FinalEventCheck().

NC::OscProb::OscPars* NCExtrapolationModule::fTrueOscPars [private]

Definition at line 176 of file NCExtrapolationModule.h.

Referenced by ApplySystematicShifts(), Config(), DoMockExperiments(), ExtrapolateNearToFar(), Run(), and ~NCExtrapolationModule().

bool NCExtrapolationModule::fUseMCAsData [private]

use the MC as data for testing purposes

Definition at line 182 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

bool NCExtrapolationModule::fUseMockData [private]

are you using mock data for the data?

Definition at line 186 of file NCExtrapolationModule.h.

Referenced by Config(), and Run().

bool NCExtrapolationModule::fUsePIDCustomCut [private]

Use custom cut.

Definition at line 189 of file NCExtrapolationModule.h.

Referenced by AddEventToExtrapolations(), and Config().


The documentation for this class was generated from the following files:
Generated on Mon Aug 11 01:06:18 2014 for loon by  doxygen 1.4.7