00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #include "TChainElement.h"
00020 #include "TFile.h"
00021 #include "TH1F.h"
00022 #include "TObjArray.h"
00023 #include "TTree.h"
00024
00025 #include "MessageService/MsgService.h"
00026
00027 #include "NtupleUtils/NuTreeWrapper.h"
00028
00029 using std::string;
00030
00031 CVSID("$Id: NuTreeWrapper.cxx,v 1.1 2007/11/15 13:44:34 evans Exp $");
00032
00033 ClassImp(NuTreeWrapper)
00034
00035 NuTreeWrapper::NuTreeWrapper()
00036 : IAmReadable(false),
00037 fcurrEntry(-1)
00038 {
00039
00040 fNuTreeWrapper = new TTree("s","s");
00041 cout<<"NuTreeWrapper::Creating new NuEvent for output to tree"<<endl;
00042 fNuEvent = new NuEvent();
00043 fNuTreeWrapper->Branch("s","NuEvent",&fNuEvent,32000,2);
00044 fInputInfo = 0;
00045 }
00046
00047
00048 NuTreeWrapper::
00049 NuTreeWrapper(string filelist
00050 = "$SRT_PRIVATE_CONTEXT/NuAntiNu/PANs/DefaultPAN.root")
00051 : IAmReadable(true),
00052 fcurrEntry(-1),
00053 fInputChain("s")
00054 {
00055
00056 cout << "Running constructor." << endl;
00057 fInputInfo = 0;
00058 fInputChain.Add(filelist.c_str());
00059 fInputChain.SetBranchAddress("s",&fInputInfo);
00060 fTotPoT = 0.0;
00061
00062 this->CalculatePoTs();
00063 }
00064
00065
00066 NuTreeWrapper::~NuTreeWrapper()
00067 {
00068 }
00069
00070
00071 void NuTreeWrapper::CalculatePoTs()
00072 {
00073 cout << "Running PoT function" << endl;
00074 TObjArray* fileList = fInputChain.GetListOfFiles();
00075 fTotPoT = 0.0;
00076 cout << "Starting fileLoop" << endl;
00077 Int_t detector = this->Detector();
00078 cout << "Got detector: " << detector << endl;
00079 for (Int_t counter=0; counter<fileList->GetEntries(); ++counter){
00080 TChainElement* chainElement =
00081 dynamic_cast<TChainElement*> (fileList->At(counter));
00082 if (chainElement){
00083 string fileName = chainElement->GetTitle();
00084 TFile f(fileName.c_str(),"READ");
00085 TH1F* hPottortgt = (TH1F*) f.Get("hPottortgt");
00086 TH1F* hRun = (TH1F*) f.Get("hRun");
00087 if (1==detector){
00088 fTotPoT += hPottortgt->GetMean()*hPottortgt->GetEntries()*1e12;
00089 }
00090 if (2==detector){
00091 fTotPoT += hPottortgt->GetMean()*hRun->GetEntries()*1e8*1e12;
00092 }
00093 fTotPoT += hPottortgt->Integral();
00094 f.Close();
00095 }
00096 }
00097 MSG("NuTreeWrapper.cxx",Msg::kInfo)
00098 << "PoT: " << fTotPoT << endl;
00099 return;
00100 }
00101
00102
00103 const Int_t NuTreeWrapper::Detector() const
00104 {
00105 if (this->GetEntriesFast()){
00106 return this->GetInfoObject(0).detector;
00107 }
00108 else{
00109 MSG("NuTreeWrapper.cxx",Msg::kError)
00110 << "Trying to get PoT for empty NuTreeWrapper" << endl;
00111 return 0;
00112 }
00113 }
00114
00115
00116 void NuTreeWrapper::FillTree()
00117 {
00118
00119 fNuTreeWrapper->Fill();
00120 }
00121
00122
00123 const Int_t NuTreeWrapper::GetEntries() const
00124 {
00125 if (!IAmReadable){
00126 MSG("NuTreeWrapper", Msg::kFatal)
00127 << "Trying to read from write-only NuTreeWrapper." << endl;
00128 return -1;
00129 }
00130 return fInputChain.GetEntries();
00131 }
00132
00133
00134 const Int_t NuTreeWrapper::GetEntriesFast() const
00135 {
00136 if (!IAmReadable){
00137 MSG("NuTreeWrapper", Msg::kFatal)
00138 << "Trying to read from write-only NuTreeWrapper." << endl;
00139 return -1;
00140 }
00141 return fInputChain.GetEntriesFast();
00142 }
00143
00144
00145 const NuEvent NuTreeWrapper::GetInfoObject(const Int_t event) const
00146 {
00147 if (!IAmReadable){
00148 MSG("NuTreeWrapper", Msg::kFatal)
00149 << "Trying to read from write-only NuTreeWrapper." << endl;
00150 NuEvent dummy;
00151 return dummy;
00152 }
00153 this->LoadEvent(event);
00154 return *fInputInfo;
00155 }
00156
00157
00158 NuEvent& NuTreeWrapper::GetObjectToFill()
00159 {
00160 fNuEvent->Reset();
00161 return *fNuEvent;
00162 }
00163
00164
00165 void NuTreeWrapper::LoadEvent(const Int_t event) const
00166 {
00167 if (event == fcurrEntry){return;}
00168 else{
00169 fInputChain.GetEvent(event);
00170 fcurrEntry = event;
00171 }
00172 }
00173
00174
00175 void NuTreeWrapper::Write(const string filename)
00176 {
00177 TFile f(filename.c_str(),"RECREATE");
00178 fNuTreeWrapper->Write();
00179 f.Close();
00180 }