00001
00002
00003
00004
00005
00006
00007
00009
00010 #include "NCUtils/Extrapolation/NCExtrapolationNone.h"
00011 #include "NCUtils/Extrapolation/NCEnergyBin.h"
00012
00013 #include "MessageService/MsgService.h"
00014
00015 #include "AnalysisNtuples/ANtpAnalysisInfo.h"
00016 #include "AnalysisNtuples/ANtpBeamInfo.h"
00017 #include "AnalysisNtuples/ANtpRecoInfo.h"
00018 #include "AnalysisNtuples/ANtpHeaderInfo.h"
00019 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00020
00021 #include "TDirectory.h"
00022 #include "TFile.h"
00023
00024 #include <cassert>
00025
00026 CVSID("$Id: NCExtrapolationNone.cxx,v 1.27 2009/09/14 13:49:53 tinti Exp $");
00027
00028 #include "NCExtrapolationModule.h"
00029
00030 REGISTER_NCEXTRAPOLATION(NCExtrapolationNone, None)
00031
00032
00033 NCExtrapolationNone::NCExtrapolationNone()
00034 {
00035 nCalls = 0;
00036
00037 fEventsTree = new TTree("sel_evts", "sel_evts");
00038
00039 fEventsTree->Branch("header.", "ANtpHeaderInfo", (void**)0);
00040 fEventsTree->Branch("beam.", "ANtpBeamInfo", (void**)0);
00041 fEventsTree->Branch("reco.", "ANtpRecoInfo", (void**)0);
00042 fEventsTree->Branch("analysis.", "ANtpAnalysisInfo", (void**)0);
00043 }
00044
00045
00046
00047
00048 NCExtrapolationNone::~NCExtrapolationNone()
00049 {
00050 MSG("NCExtrapolationNone", Msg::kInfo) << nCalls << " calls in total to NCExtrapolationNone" << endl;
00051
00052 if(fEventsTree) delete fEventsTree;
00053 }
00054
00055
00056 const Registry& NCExtrapolationNone::DefaultConfig()
00057 {
00058 static Registry r;
00059
00060 r.UnLockValues();
00061
00062 r.Set("SelectedEventsFilename", "/tmp/sel_evts.root");
00063
00064 r.LockValues();
00065 return r;
00066 }
00067
00068 void NCExtrapolationNone::Prepare(const Registry& r)
00069 {
00070 NCExtrapolation::Prepare(r);
00071
00072 const char* tmps;
00073 if(r.Get("SelectedEventsFilename", tmps)) fSelEvtsFname = tmps;
00074 }
00075
00076
00077
00078
00079
00080 void NCExtrapolationNone::AddEvent(NCEventInfo info,
00081 bool useMCAsData,
00082 NCType::EFileType fileType,
00083 NCBeam::Info beamInfo)
00084 {
00085
00086 NCExtrapolation::AddEvent(info, useMCAsData, fileType, beamInfo);
00087
00088
00089
00090 if(info.reco->inFiducialVolume < 1 ||
00091 (info.header->detector == int(Detector::kNear) &&
00092 info.reco->isSimpleCutsClean < 1))
00093 return;
00094
00095 if(info.header->dataType != int(SimFlag::kData)) return;
00096
00097 assert(fEventsTree);
00098 fEventsTree->SetBranchAddress("header.", &info.header);
00099 fEventsTree->SetBranchAddress("beam.", &info.beam);
00100 fEventsTree->SetBranchAddress("reco.", &info.reco);
00101 fEventsTree->SetBranchAddress("analysis.", &info.analysis);
00102
00103 fEventsTree->Fill();
00104 }
00105
00106
00107 void NCExtrapolationNone::FillMCSpectrum(TH1* exp,
00108 const NCEnergyBin* bin,
00109 InfoFunction func,
00110 int size,
00111 const NC::OscProb::OscPars* pars,
00112 NCType::EEventType nccc,
00113 NCType::EOscMode oscmode)
00114 {
00115 for(int e = 0; e < size; ++e){
00116 double trueE, showerE, trackE, weight;
00117 int flavour;
00118
00119
00120 (bin->*func)(trueE, showerE, trackE, weight, flavour, e);
00121
00122 const double oscweight = pars->TransitionProbability(oscmode,
00123 nccc,
00124 NCType::kBaseLineFar,
00125 trueE);
00126
00127 exp->Fill(showerE+trackE, weight*oscweight);
00128 }
00129 }
00130
00131
00132
00133 void NCExtrapolationNone::
00134 FindSpectraForPars(const NC::OscProb::OscPars* oscPars,
00135 const NC::SystPars& systPars,
00136 vector<NCBeam::Info> ,
00137 vector<TH1*>& expvec,
00138 vector<TH1*>& obsvec)
00139 {
00140 ++nCalls;
00141
00142 const double norm = systPars.NormScale();
00143
00144 static TH1D* obsCache[2] = {0, 0};
00145
00146
00147
00148 NCBeam* beam = GetBeam(Detector::kFar,
00149 NCBeam::Info(BeamType::kL010z185i,
00150 NC::RunUtil::kRunAll));
00151
00152 for(int nccci = 0; nccci < 2; ++nccci){
00153 NCType::EEventType nccc;
00154 if(nccci == 0) nccc = NCType::kNC; else nccc = NCType::kCC;
00155
00156 if(nccc == NCType::kNC && !fUseNC) continue;
00157 if(nccc == NCType::kCC && !fUseCC) continue;
00158
00159 if(!obsCache[nccci]){
00160 obsCache[nccci] = new TH1D("", "", kNumEnergyBinsFar,
00161 kEnergyBinsFar);
00162 for(int b = 0; b < beam->GetNumberEnergyBins(nccc); ++b){
00163 const NCEnergyBin* bin = beam->GetEnergyBin(b, nccc);
00164
00165 const int dataSize = bin->GetDataVectorSize();
00166
00167 for(int e = 0; e < dataSize; ++e){
00168 double energy, weight;
00169 bin->GetDataInformation(energy, weight, e);
00170
00171 obsCache[nccci]->Fill(energy, weight);
00172 }
00173 }
00174 }
00175
00176 TH1D* obs = obsCache[nccci];
00177
00178 TH1D* exp = new TH1D("", "", kNumEnergyBinsFar,
00179 kEnergyBinsFar);
00180
00181 for(int b = 0; b < beam->GetNumberEnergyBins(nccc); ++b){
00182 const NCEnergyBin* bin = beam->GetEnergyBin(b, nccc);
00183
00184 FillMCSpectrum(exp, bin, &NCEnergyBin::GetMCInformation,
00185 bin->GetMCSignalVectorSize(),
00186 oscPars, nccc, NCType::kNuMuToNuMu);
00187
00188 const NCType::EEventType bgtype = (nccc == NCType::kNC) ? NCType::kCC : NCType::kNC;
00189
00190 FillMCSpectrum(exp, bin, &NCEnergyBin::GetMCBackgroundInformation,
00191 bin->GetMCBackgroundVectorSize(),
00192 oscPars, bgtype, NCType::kNuMuToNuMu);
00193
00194 FillMCSpectrum(exp, bin, &NCEnergyBin::GetMCNuTauInformation,
00195 bin->GetMCNuTauVectorSize(),
00196 oscPars, nccc, NCType::kNuMuToNuTau);
00197
00198 FillMCSpectrum(exp, bin, &NCEnergyBin::GetMCBeamNuEInformation,
00199 bin->GetMCBeamNuEVectorSize(),
00200 oscPars, nccc, NCType::kNuEToNuE);
00201
00202
00203
00204 exp->Scale(norm);
00205
00206 }
00207
00208 expvec.push_back(exp);
00209 obsvec.push_back(obs);
00210 }
00211
00212 assert(expvec.size() == obsvec.size());
00213 }
00214
00215
00216
00217 void NCExtrapolationNone::CleanupSpectra(vector<TH1*> expvec,
00218 vector<TH1*> )
00219 {
00220 for(unsigned int n = 0; n < expvec.size(); ++n) delete expvec[n];
00221 }
00222
00223
00224
00225 void NCExtrapolationNone::
00226 WriteResources(const NC::OscProb::OscPars* trueOscPars)
00227 {
00228 NCExtrapolation::WriteResources(trueOscPars);
00229
00230 TDirectory* fileDir = gDirectory;
00231
00232 TFile f(fSelEvtsFname, "RECREATE");
00233 fEventsTree->Write();
00234 f.Close();
00235
00236 fileDir->cd();
00237 }