00001 #include "TChain.h"
00002 #include "TChainElement.h"
00003 #include "TFile.h"
00004 #include "TObjArray.h"
00005
00006 #include "MessageService/MsgService.h"
00007 #include "NtupleUtils/NuFCEvent.h"
00008 #include "NtupleUtils/NuMMParameters.h"
00009 #include "NtupleUtils/NuShiftableUnbinnedSpectrum.h"
00010 #include "NtupleUtils/NuTreeWrapper.h"
00011
00012 ClassImp(NuShiftableUnbinnedSpectrum)
00013
00014 CVSID("$Id: NuShiftableUnbinnedSpectrum.cxx,v 1.1 2008/10/17 11:47:03 evansj Exp $");
00015
00016
00017 NuShiftableUnbinnedSpectrum::NuShiftableUnbinnedSpectrum()
00018 : NuShiftableSpectrum(),
00019 fCharge(1),
00020 fBinningScheme(NuBinningScheme::kNuMuBar0325Std2)
00021 {
00022 }
00023
00024
00025 NuShiftableUnbinnedSpectrum
00026 ::NuShiftableUnbinnedSpectrum(const std::string filename)
00027 : NuShiftableSpectrum(),
00028 fCharge(1)
00029 {
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 TChain fcDST("FCTree");
00045 fcDST.Add(filename.c_str());
00046 NuFCEvent* fcEvent = 0;
00047 fcDST.SetBranchAddress("NuFCEvent",&fcEvent);
00048 Int_t numEntries = fcDST.GetEntries();
00049 for (Int_t entry=0; entry<numEntries; ++entry){
00050 fcDST.GetEvent(entry);
00051 if (this->Charge() == fcEvent->charge || 0==this->Charge()){
00052 NuMiniEvent miniEvent;
00053 miniEvent.recoTrackEnergy = fcEvent->trkEn;
00054 miniEvent.recoNuEnergy = fcEvent->energy;
00055 fEventList.push_back(miniEvent);
00056 }
00057 }
00058
00059 TObjArray* fileList = fcDST.GetListOfFiles();
00060 Double_t totPoT = 0.0;
00061 for (Int_t counter=0; counter<fileList->GetEntries(); ++counter){
00062 TChainElement* chainElement =
00063 dynamic_cast<TChainElement*> (fileList->At(counter));
00064 if (chainElement){
00065 string fileName = chainElement->GetTitle();
00066 TFile f(fileName.c_str(),"READ");
00067 TH1F* hTotalPot = (TH1F*) f.Get("hTotalPot");
00068 if (hTotalPot){
00069 totPoT += hTotalPot->Integral();
00070 }
00071 f.Close();
00072 }
00073 }
00074 this->PoT(totPoT);
00075 MSG("NuTreeWrapper.cxx",Msg::kInfo)
00076 << "PoT: " << totPoT << endl;
00077 }
00078
00079
00080 const TH1D NuShiftableUnbinnedSpectrum::Spectrum(const NuMMParameters& pars) const
00081 {
00082 return this->Spectrum(pars.ShwEnScale());
00083 }
00084
00085
00086 const TH1D NuShiftableUnbinnedSpectrum::Spectrum(const Double_t shift) const
00087 {
00088 const NuUtilities utils;
00089 const vector<Double_t> recoBins = utils.RecoBins(fBinningScheme);
00090 const Int_t numRecoBins = recoBins.size()-1;
00091 Float_t *recoBinsArray;
00092 recoBinsArray=new Float_t[numRecoBins+1];
00093 {
00094 Int_t i=0;
00095 for (vector<Double_t>::const_iterator itBin = recoBins.begin();
00096 itBin != recoBins.end();
00097 ++itBin, ++i){
00098 recoBinsArray[i] = *itBin;
00099 }
00100 }
00101 TH1D outSpectrum("RecoEnergy_FD","",
00102 numRecoBins,recoBinsArray);
00103
00104 for (vector<NuMiniEvent>::const_iterator it = fEventList.begin();
00105 it != fEventList.end();
00106 ++it){
00107 Double_t energy = it->recoNuEnergy;
00108 Double_t trkEn = it->recoTrackEnergy;
00109 Double_t shiftedEnergy = energy + shift*trkEn;
00110 outSpectrum.Fill(shiftedEnergy);
00111 }
00112
00113 return outSpectrum;
00114 }