NuBase Class Reference

#include <NuBase.h>

Inheritance diagram for NuBase:

NuAnalysis NuDSTAna DataMCPlots FitTree FoverNHistos TemplateAnalysisClass ToFPlotter List of all members.

Public Member Functions

 NuBase ()
virtual ~NuBase ()
void Test ()
void TestEventLoop ()
virtual void WriteOutHistos ()
virtual void OpenOutFile (TString outName, TString opt="RECREATE")
virtual void CloseOutFile ()
Bool_t ObjectExistsInFile (TFile *file, std::string objectName) const
std::string GetFirstFileName (std::string wildcardString) const
TFile * OpenFile (Int_t runNumber, std::string prefix) const
TFile * OpenFile (const NuConfig &config, std::string prefix) const
TFile * OpenFileRECREATE (std::string sFileName) const
ofstream * OpenTxtFile (Int_t runNumber, std::string prefix) const
ofstream * OpenTxtFile (const NuConfig &config, std::string prefix) const

Static Public Member Functions

static void InputFileName (std::string f)
static void LoadTrees (Bool_t loadTrees)

Protected Member Functions

Float_t GetEntries () const
Int_t GetNumFilesAddedToChain () const
const NtpStRecordGetNtpStRecord () const
const NtpBDLiteRecordGetNtpBDLiteRecord () const
std::string GetFirstFileName () const
std::string GetInputFileName () const
TFile * GetOutputFile () const
void PrintLoopProgress (Int_t entry, Float_t nEntries, Int_t printMode) const
void InitialiseLoopVariables ()
void SetLoopVariables (Int_t event, Int_t printMode=1)

Protected Attributes

TFile * fOutFile

Private Member Functions

void MakeChain ()
std::vector< std::string > MakeFileList ()
void SetRootFileObjects ()

Private Attributes

TChain * fChain
TChain * fChainBD
NtpStRecordfRec
NtpBDLiteRecordfRecBD
Float_t fEntries
Float_t fEntriesBD
Int_t fRun
Int_t fSubrun
Int_t fNumFiles
std::string fFirstFileName
std::string fS

Static Private Attributes

static std::string fInputFileName = ""
static Bool_t fLoadTrees = true

Detailed Description

Definition at line 28 of file NuBase.h.


Constructor & Destructor Documentation

NuBase::NuBase (  ) 

Definition at line 45 of file NuBase.cxx.

References fChain, fChainBD, fEntries, fEntriesBD, fFirstFileName, fLoadTrees, fNumFiles, fOutFile, fRec, fRecBD, fRun, fS, fSubrun, RecRecordImp< T >::GetHeader(), RecDataHeader::GetRun(), RecDataHeader::GetSubRun(), Msg::kInfo, MakeChain(), MSG, and SetRootFileObjects().

00046 {
00047   MSG("NuBase",Msg::kInfo)
00048     <<"Running NuBase Constructor..."<<endl;
00049 
00050   fChain=0;
00051   fChainBD=0;
00052   fOutFile=0;
00053   fRec=0;//sr
00054   fRecBD=0;//sr beam data
00055   
00056   fEntries=0;
00057   fEntriesBD=0;
00058   fRun=100;//default
00059   fSubrun=0;
00060 
00061   fNumFiles=0;//number of files added to chain
00062   
00063   fFirstFileName="";
00064   fS="";//general purpose string
00065 
00066 
00067   if (fLoadTrees) {
00068     MSG("NuBase",Msg::kInfo)<<"Loading trees"<<endl;
00069     this->MakeChain();
00070     this->SetRootFileObjects();
00071     //this->InitialiseHitInfoVariables();
00072     
00073     //get basic run number stuff
00074     if (fRec && fChain){//sr
00075       //get the first event
00076       fChain->GetEvent(0); 
00077       NtpStRecord& ntp=(*fRec);
00078       const RecCandHeader& rec=ntp.GetHeader();
00079       MSG("NuBase",Msg::kInfo)
00080         <<"Found: run="<<rec.GetRun()
00081         <<", subrun="<<rec.GetSubRun()<<endl;
00082       fRun=rec.GetRun();
00083       fSubrun=rec.GetSubRun();
00084     }
00085     else cout<<"Ahhh, no root files"<<endl;
00086   }
00087   else  MSG("NuBase",Msg::kInfo)<<"Not loading trees"<<endl;
00088 
00089   //setup some root stuff
00090   //include the under and overflow counts
00091   gStyle->SetOptStat(1111111);
00092   gStyle->SetOptFit(1111);
00093   gStyle->SetPalette(1);
00094   
00095   MSG("NuBase",Msg::kInfo)
00096     <<"Finished NuBase Constructor"<<endl;
00097 }

NuBase::~NuBase (  )  [virtual]

Definition at line 101 of file NuBase.cxx.

References fOutFile, Msg::kDebug, Msg::kInfo, and MSG.

00102 {
00103   MSG("NuBase",Msg::kInfo)
00104     <<"Running NuBase Destructor..."<<endl;
00105   
00106   if (fOutFile){
00107     //this makes histos disappear from the canvases 
00108     //so do it at the very end
00109     fOutFile->Close();
00110   }
00111   
00112   MSG("NuBase",Msg::kDebug)
00113     <<"Finished NuBase Destructor"<<endl;
00114 }


Member Function Documentation

void NuBase::CloseOutFile (  )  [virtual]

Definition at line 200 of file NuBase.cxx.

References fOutFile.

00201 {
00202   if (fOutFile) fOutFile->Close();
00203 }

Float_t NuBase::GetEntries (  )  const [inline, protected]

Definition at line 62 of file NuBase.h.

References fEntries.

Referenced by NuAnalysis::BasicPlots(), NuAnalysis::ChargeSeparation(), NuAnalysis::ChargeSignCut(), NuAnalysis::Efficiencies(), NuAnalysis::EfficienciesOld(), NuAnalysis::EnergySpect(), NuAnalysis::EnergySpectMC(), NuAnalysis::LIRejectionTest(), NuAnalysis::N_1(), and NuAnalysis::NuMuBarAppearance().

00062 {return fEntries;};

std::string NuBase::GetFirstFileName (  )  const [inline, protected]

Definition at line 66 of file NuBase.h.

References fFirstFileName.

Referenced by MakeChain().

00066 {return fFirstFileName;};  

std::string NuBase::GetFirstFileName ( std::string  wildcardString  )  const

Definition at line 323 of file NuBase.cxx.

References Form(), and gSystem().

00324 {
00325   //check if there is actually a wildcard
00326   if (!TString(wildcardString.c_str()).MaybeWildcard()) {
00327     return wildcardString;
00328   }
00329   
00330   //this was ripped off from ROOT's TChain::AddFile
00331 
00332   vector<string> fileList;
00333 
00334   //wildcarding used in name
00335   TString basename(wildcardString.c_str());
00336 
00337   Int_t dotslashpos = basename.Index(".root/");
00338   TString behind_dot_root;
00339   if (dotslashpos>=0) {
00340     // Copy the tree name specification
00341     behind_dot_root = basename(dotslashpos+6,basename.Length()-dotslashpos+6);
00342     // and remove it from basename
00343     basename.Remove(dotslashpos+5);
00344   }
00345 
00346   Int_t slashpos = basename.Last('/');
00347   TString directory;
00348   if (slashpos>=0) {
00349     directory = basename(0,slashpos); // Copy the directory name
00350     basename.Remove(0,slashpos+1);      // and remove it from basename
00351   } else {
00352     directory = gSystem->WorkingDirectory();
00353   }
00354 
00355   const char *file;
00356   void *dir = gSystem->OpenDirectory(gSystem->ExpandPathName(directory.Data()));
00357 
00358   if (dir) {
00359     //create a TList to store the file names (not yet sorted)
00360     TList l;
00361     TRegexp re(basename,kTRUE);
00362     while ((file = gSystem->GetDirEntry(dir))) {
00363       if (!strcmp(file,".") || !strcmp(file,"..")) continue;
00364       TString s = file;
00365       if ( (basename!=file) && s.Index(re) == kNPOS) continue;
00366       l.Add(new TObjString(file));
00367     }
00368     gSystem->FreeDirectory(dir);
00369     //sort the files in alphanumeric order
00370     l.Sort();
00371     TIter next(&l);
00372     TObjString *obj;
00373     while ((obj = (TObjString*)next())) {
00374       file = obj->GetName();
00375       if (behind_dot_root.Length()!=0){
00376         string fileName=Form("%s/%s/%s",directory.Data(),
00377                              file,behind_dot_root.Data());
00378         fileList.push_back(fileName);
00379         //nf += AddFile(Form("%s/%s/%s",directory.Data(),file,behind_dot_root.Data()),kBigNumber);
00380       }
00381       else {
00382         string fileName=Form("%s/%s",directory.Data(),file);
00383         fileList.push_back(fileName);
00384         //nf += AddFile(Form("%s/%s",directory.Data(),file),kBigNumber);
00385       }
00386     }
00387     l.Delete();
00388   }
00389 
00390   //check if any files were found
00391   if (fileList.begin()!=fileList.end()){
00392     cout<<"Used wildcard expansion to find first file name="
00393         <<*fileList.begin()<<endl;
00394     return *fileList.begin();
00395   }
00396   else {
00397     return "";//null string
00398   }
00399 }

std::string NuBase::GetInputFileName (  )  const [inline, protected]

Definition at line 67 of file NuBase.h.

References fInputFileName.

Referenced by NuDSTAna::DoIO(), NuDSTAna::DoIOSimple(), NuAnalysis::ExtractConfig(), NuDSTAna::FDTestAna(), and NuDSTAna::NMBAna().

00067 {return fInputFileName;};  

const NtpBDLiteRecord* NuBase::GetNtpBDLiteRecord (  )  const [inline, protected]

Definition at line 65 of file NuBase.h.

References fRecBD.

Referenced by NuAnalysis::ChargeSeparation(), and NuAnalysis::ExtractConfig().

00065 {return fRecBD;};

const NtpStRecord* NuBase::GetNtpStRecord (  )  const [inline, protected]

Definition at line 64 of file NuBase.h.

References fRec.

Referenced by NuAnalysis::BasicPlots(), NuAnalysis::ChargeSignCut(), NuAnalysis::Efficiencies(), NuAnalysis::EfficienciesOld(), NuAnalysis::EnergySpect(), NuAnalysis::EnergySpectMC(), NuAnalysis::LIRejectionTest(), NuAnalysis::N_1(), and NuAnalysis::NuMuBarAppearance().

00064 {return fRec;};

Int_t NuBase::GetNumFilesAddedToChain (  )  const [inline, protected]

Definition at line 63 of file NuBase.h.

References fNumFiles.

Referenced by NuAnalysis::Efficiencies(), NuAnalysis::NuMuBarAppearance(), and WriteOutHistos().

00063 {return fNumFiles;};

TFile* NuBase::GetOutputFile (  )  const [inline, protected]

Definition at line 68 of file NuBase.h.

References fOutFile.

00068 {return fOutFile;}; 

void NuBase::InitialiseLoopVariables (  )  [protected]

Definition at line 902 of file NuBase.cxx.

References Msg::kDebug, and MSG.

Referenced by NuAnalysis::BasicPlots(), NuAnalysis::ChargeSeparation(), NuAnalysis::ChargeSignCut(), NuAnalysis::Efficiencies(), NuAnalysis::EfficienciesOld(), NuAnalysis::EnergySpect(), NuAnalysis::EnergySpectMC(), NuAnalysis::LIRejectionTest(), NuAnalysis::N_1(), NuAnalysis::NuMuBarAppearance(), and TestEventLoop().

00903 {
00904   MSG("NuBase",Msg::kDebug)<<"Initialising loop variables..."<<endl;
00905 
00906   MSG("NuBase",Msg::kDebug)<<"Initialisation complete"<<endl;
00907 }

static void NuBase::InputFileName ( std::string  f  )  [static]

Referenced by NuModule::Ana().

void NuBase::LoadTrees ( Bool_t  loadTrees  )  [static]

Definition at line 129 of file NuBase.cxx.

References fLoadTrees.

00130 {
00131   fLoadTrees=loadTrees;
00132 }

void NuBase::MakeChain (  )  [private]

Definition at line 403 of file NuBase.cxx.

References fChain, fChainBD, fFirstFileName, fNumFiles, GetFirstFileName(), Msg::kFatal, Msg::kInfo, MakeFileList(), MAXMSG, and MSG.

Referenced by NuBase().

00404 {
00405   //get the files to open
00406   vector<string> fileList=this->MakeFileList();
00407 
00408   TFile* firstFile=0;
00409   // case with one single file
00410   if (!TString(*fileList.begin()).MaybeWildcard()) {
00411     fFirstFileName=(*fileList.begin());//store first filename
00412     firstFile=TFile::Open((*fileList.begin()).c_str(),"READ");
00413   }
00414   else {
00415     MSG("NuBase",Msg::kInfo)
00416       <<"Found a wildcard present in list of file names: "
00417       <<*fileList.begin()
00418       <<endl<<"Looking for first filename using wildcard..."<<endl;
00419     string fileName=this->GetFirstFileName(*fileList.begin());
00420     fFirstFileName=fileName;//store first filename
00421     if (fileName!="") {
00422       firstFile=TFile::Open(fileName.c_str(),"READ");
00423     }
00424     else {
00425       MSG("NuBase",Msg::kInfo)
00426         <<"No files found matching:"<<endl
00427         <<*fileList.begin()<<", will exit here..."<<endl;
00428       exit(1);
00429     }
00430   }
00431   
00432   //create a chain
00433   //check if the SR ntuple exists
00434   if (this->ObjectExistsInFile(firstFile,"NtpSt")) {
00435     fChain=new TChain("NtpSt");
00436   }
00437   else {
00438     MSG("NuBase",Msg::kInfo)
00439       <<"Not creating NtpSt TChain because it does not exist in file"
00440       <<endl;
00441   }
00442   
00443   //check in BD ntuple exists
00444   if (this->ObjectExistsInFile(firstFile,"NtpBDLite")) {
00445     fChainBD=new TChain("NtpBDLite");//have to load libraries too
00446   }
00447   else {
00448     MSG("NuBase",Msg::kInfo)
00449       <<"Not creating NtpBDLite TChain because it does not exist"
00450       <<" in file"<<endl;
00451   }
00452   
00453   firstFile->Close();
00454   if (firstFile) delete firstFile;
00455   firstFile=0;
00456 
00457   Int_t nf=0;
00458   Int_t nfBD=0;
00459   //add the files to the chain
00460   for (vector<string>::iterator file=fileList.begin();
00461        file!=fileList.end();++file){
00462     
00463     //test if file exists
00464     Bool_t openOk=false;
00465     //can't test dcache files are open so assume it's fine
00466     if ((*file).find("dcache")!=string::npos) {//check for null position
00467       MAXMSG("NuBase",Msg::kInfo,3)
00468         <<"Filename contains \"dcache\" in path"
00469         <<" so not testing its existance"<<endl;
00470       openOk=true;
00471     }
00472     else {
00473       ifstream fileOpenOk((*file).c_str()); 
00474       openOk=fileOpenOk;
00475     }
00476 
00477     //check if a wildcard was used because ifstream can't open wildcards
00478     Int_t stars=(*file).find("*");
00479     Int_t quest=(*file).find("?");
00480 
00481     //check if file existed
00482     if (!openOk && !(quest>=0 || stars>=0)){
00483       MSG("NuBase",Msg::kInfo)
00484         <<endl<<endl
00485         <<"***********************************************************"
00486         <<endl<<"Can't find file="<<*file<<endl
00487         <<"Note: you can't use '~/'. It has to be the full path"<<endl
00488         <<"***********************************************************"
00489         <<endl<<endl
00490         <<"Exiting here!"<<endl;
00491       exit(0);
00492     }
00493     
00494     MSG("NuBase",Msg::kInfo)<<"Adding file(s)="<<*file<<endl;
00495     nf+=fChain->Add((*file).c_str());
00496     if (fChainBD) nfBD+=fChainBD->Add((*file).c_str());
00497     //fChain->Print();//very verbose
00498   }
00499 
00500   if(nf==0){
00501     MSG("NuBase",Msg::kFatal)
00502       <<endl<<endl
00503       <<"*************************************************************"
00504       <<endl<<"No *.root files found"<<endl
00505       <<"Please set NUDATA to the directory containing the"
00506       <<" *.root files"<<endl
00507       <<"Or give the txt file containing the files to be input"<<endl
00508       <<"Note: If more than one file is found they will be"
00509       <<" concatenated in a TChain and treated as one"<<endl
00510       <<"*************************************************************"
00511       <<endl<<endl<<"Program will exit here"<<endl;
00512     exit(0);
00513   }
00514   
00515   MSG("NuBase",Msg::kInfo)
00516     <<endl<<"Added "<<nf<<" file(s) to TChain"<<endl;
00517   MSG("NuBase",Msg::kInfo)
00518     <<endl<<"Added "<<nfBD<<" beam data (BD) file(s) to TChain"
00519     <<endl;
00520   
00521   if (fChain) {
00522     MSG("NuBase",Msg::kInfo) 
00523       <<"Ntuple information:"<<endl;
00524     fChain->Show(0);
00525     
00526     if (fChainBD) {
00527       MSG("NuBase",Msg::kInfo) 
00528         <<"NtpBDLite information:"<<endl;
00529       fChainBD->Show(0);
00530     }
00531   }
00532   
00533   MSG("NuBase",Msg::kInfo)
00534     <<endl<<"Added "<<nfBD<<" beam data (BD) file(s) to TChain."
00535     <<endl;
00536   MSG("NuBase",Msg::kInfo)
00537     <<endl<<"Analysing "<<nf<<" file(s). Reading from disk..."<<endl;
00538 
00539   //set the class data member
00540   fNumFiles=nf;
00541 }

vector< string > NuBase::MakeFileList (  )  [private]

Definition at line 207 of file NuBase.cxx.

References fInputFileName, Msg::kDebug, Msg::kFatal, Msg::kInfo, and MSG.

Referenced by MakeChain().

00208 {
00210 
00211   vector<string> fileList;
00212   
00213   if (fInputFileName!=""){
00214 
00215     Int_t findGives=fInputFileName.find(".root");
00216     MSG("NuBase",Msg::kInfo)
00217       <<"Checking input string for \"*.root\", position in string="
00218       <<findGives<<endl;
00219 
00220     if (findGives>0){
00221       //add the file direct to the list
00222       fileList.push_back(fInputFileName);
00223     }
00224     else{//treat the file as a list of root files 
00225       ifstream inputFile(fInputFileName.c_str());
00226       
00227       //check if file exists
00228       if (inputFile){
00229         //variables to hold input from file
00230         string file="";
00231         
00232         //read in from the text file and fill objects
00233         while(inputFile>>file) {
00234           MSG("NuBase",Msg::kDebug)
00235             <<"Found input file name="<<file<<endl;
00236           fileList.push_back(file);
00237         }
00238         MSG("NuBase",Msg::kDebug)
00239           <<"Files names found in txt file="<<fileList.size()<<endl;
00240       }
00241       else{
00242         MSG("NuBase",Msg::kFatal)
00243           <<endl<<endl
00244           <<"**********************************************************"
00245           <<endl<<"Input txt file of file names does not exist!"<<endl
00246           <<"InputFileName="<<fInputFileName<<endl
00247           <<"**********************************************************"
00248           <<endl<<endl<<"Program will exit here"<<endl;
00249         exit(0);
00250       }
00251     }
00252   }
00253   //return the fileList if files were found
00254   if (fileList.size()>0) return fileList;
00255   
00256   //Check the env variable to find files
00257   char* envVariable=getenv("NUDATA");
00258   if (envVariable==NULL){
00259     MSG("NuBase",Msg::kFatal)
00260       <<endl<<endl
00261       <<"*************************************************************"
00262       <<endl<<"Environmental variable NUDATA not set!"<<endl
00263       <<"Please set NUDATA to the directory containing the"
00264       <<" ntuple root files"<<endl
00265       <<"Note: If more than one file is found they will be"
00266       <<" concatenated and treated as one"<<endl
00267       <<"*************************************************************"
00268       <<endl<<endl<<"Program will exit here"<<endl;
00269     exit(0);
00270   }
00271 
00272   string sEnv="";
00273   sEnv=envVariable;
00274   sEnv+="/*.root";
00275   MSG("NuBase",Msg::kInfo)
00276     <<"Looking for *.root files using the env variable"<<endl
00277     <<"NUDATA="<<sEnv<<endl;    
00278   fileList.push_back(sEnv);
00279 
00280   return fileList;
00281 }

Bool_t NuBase::ObjectExistsInFile ( TFile *  file,
std::string  objectName 
) const

Definition at line 286 of file NuBase.cxx.

References Msg::kInfo, Msg::kWarning, and MSG.

00288 {
00289   if (!file) {
00290     MSG("NuBase",Msg::kWarning)
00291       <<"File does not exist so can't test if object exists!"<<endl;
00292     return false;
00293   }
00294 
00295   TList* listOfKeys=file->GetListOfKeys();
00296 
00297   static TFile* lastFile=0;
00298   if (lastFile!=file){
00299     MSG("NuBase",Msg::kInfo)
00300       <<"File contains these keys:"<<endl;
00301     listOfKeys->Print();
00302   }
00303   lastFile=file;
00304 
00305   TObject* ob=listOfKeys->FindObject(objectName.c_str());
00306   if (ob) {
00307     MSG("NuBase",Msg::kInfo)
00308       <<"Requested object with name="<<objectName
00309       <<" exists in file:"<<endl;
00310     ob->Print();
00311     return true;
00312   }
00313   else {
00314     MSG("NuBase",Msg::kInfo)
00315       <<"Requested object with name="<<objectName
00316       <<" does NOT exist in file"<<endl;
00317     return false;
00318   }
00319 }

TFile * NuBase::OpenFile ( const NuConfig config,
std::string  prefix 
) const

Definition at line 585 of file NuBase.cxx.

References NuConfig::detector, Form(), Detector::kCalDet, Detector::kFar, Msg::kInfo, SimFlag::kMC, Detector::kNear, MSG, NuConfig::run, NuConfig::simFlag, and Test().

00586 {
00587   //call this static function to ensure any histograms created
00588   //after the file is opened are added
00589   TH1::AddDirectory(true);
00590 
00591   //create the tfile pointer to be returned
00592   TFile* outputFile=0;
00593   
00594   //get the environmental variable
00595   char *anaDir=getenv("NUANA_DIR");
00596   
00597   //use a string to hold env instead 
00598   string sAnaDir="";
00599   
00600   if (anaDir!=NULL) {
00601     sAnaDir=anaDir;
00602   }
00603   else {
00604     MSG("NuBase",Msg::kInfo) 
00605       <<"Environmental variable $NUANA_DIR not set." 
00606       <<" Writing file(s) to current directory"<<endl;
00607     sAnaDir=".";
00608   }
00609   
00610   //convert variables to string
00611   string sRunNumber=Form("%d",config.run);
00612   string sZeros="";
00613   if (config.run>=0 && config.run<10) sZeros="00000000";
00614   else if (config.run>=10 && config.run<100) sZeros="000000";
00615   else if (config.run>=100 && config.run<1000) sZeros="00000";
00616   else if (config.run>=1000 && config.run<10000) sZeros="0000";
00617   else if (config.run>=10000 && config.run<100000) sZeros="000";
00618   else if (config.run>=100000 && config.run<1000000) sZeros="00";
00619   else if (config.run>=1000000 && config.run<10000000) sZeros="0";
00620   else if (config.run>=10000000 && config.run<100000000) sZeros="";
00621   sRunNumber=sZeros+sRunNumber;
00622 
00623   string sDetector="UnknownDet";
00624   if (config.detector==Detector::kNear) {
00625     sDetector="N";
00626     if (config.simFlag==SimFlag::kMC) sDetector="n";
00627   }
00628   else if (config.detector==Detector::kFar) {
00629     sDetector="F";
00630     if (config.simFlag==SimFlag::kMC) sDetector="f";
00631   }
00632   else if (config.detector==Detector::kCalDet) {
00633     sDetector="C";
00634     if (config.simFlag==SimFlag::kMC) sDetector="c";
00635   }
00636   else cout<<"Ahhh, don't know detector="<<config.detector<<endl;
00637   
00638   string sPrefix="";//default
00639   if (prefix!="") sPrefix+=prefix;
00640   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00641   string sFileName=sBase+".root";
00642   
00643   //test if file already exists
00644   ifstream Test(sFileName.c_str());
00645   
00646   //open the appropriate file
00647   if(!Test){
00648     outputFile=new TFile(sFileName.c_str(),"RECREATE");
00649   }
00650   else {
00651     //Need new filename
00652     Int_t fred=1;
00653     while(Test) {
00654       Test.close();
00655       string sAppendage=Form("%d",fred);
00656       sFileName=sBase+"_"+sAppendage+".root";
00657       Test.open(sFileName.c_str());
00658       fred++;
00659     }
00660     outputFile=new TFile(sFileName.c_str(),"NEW");
00661     outputFile->SetCompressionLevel(9);
00662   }
00663   
00664   string sTmp="No File!";
00665   if (outputFile) sTmp=outputFile->GetName();
00666 
00667   //this is a simple histogram for passing out an error code
00668   //to the output file if it occured
00669   //it is meant to be used only to flag errors and to make the
00670   //user go and look in the log file
00671   TH1F* hError=new TH1F("hError","hError",110,-10,100);
00672   hError->GetXaxis()->SetTitle("Error code");
00673   hError->GetXaxis()->CenterTitle();
00674 
00675   MSG("NuBase",Msg::kInfo) 
00676     <<"Output file opened: "<<sTmp<<endl;
00677   return outputFile;
00678 }

TFile * NuBase::OpenFile ( Int_t  runNumber,
std::string  prefix 
) const

Definition at line 682 of file NuBase.cxx.

References Form(), Msg::kInfo, MSG, and Test().

Referenced by NuAnalysis::BasicPlots(), NuAnalysis::ChargeSignCut(), NuAnalysis::CrossSections(), NuDSTAna::DoIO(), NuDSTAna::DoIOSimple(), NuAnalysis::Efficiencies(), NuAnalysis::EfficienciesOld(), NuAnalysis::EnergySpect(), NuAnalysis::EnergySpectMC(), NuDSTAna::FDTestAna(), NuAnalysis::LIRejectionTest(), NuAnalysis::N_1(), NuDSTAna::NMBAna(), NuAnalysis::NMBSummaryTreeAna(), and NuAnalysis::NuMuBarAppearance().

00683 {
00684   //call this static function to ensure any histograms created
00685   //after the file is opened are added
00686   TH1::AddDirectory(true);
00687 
00688   //create the tfile pointer to be returned
00689   TFile* outputFile=0;
00690   
00691   //get the environmental variable
00692   char *anaDir=getenv("NUANA_DIR");
00693   
00694   //use a string to hold env instead 
00695   string sAnaDir="";
00696   
00697   if (anaDir!=NULL) {
00698     sAnaDir=anaDir;
00699   }
00700   else {
00701     MSG("NuBase",Msg::kInfo) 
00702       <<"Environmental variable $NUANA_DIR not set." 
00703       <<" Writing file(s) to current directory"<<endl;
00704     sAnaDir=".";
00705   }
00706   
00707   //convert variables to string
00708   string sRunNumber=Form("%d",runNumber);
00709   string sZeros="";
00710   if (runNumber>=0 && runNumber<10) sZeros="00000000";
00711   else if (runNumber>=10 && runNumber<100) sZeros="000000";
00712   else if (runNumber>=100 && runNumber<1000) sZeros="00000";
00713   else if (runNumber>=1000 && runNumber<10000) sZeros="0000";
00714   else if (runNumber>=10000 && runNumber<100000) sZeros="000";
00715   else if (runNumber>=100000 && runNumber<1000000) sZeros="00";
00716   else if (runNumber>=1000000 && runNumber<10000000) sZeros="0";
00717   else if (runNumber>=10000000 && runNumber<100000000) sZeros="";
00718   sRunNumber=sZeros+sRunNumber;
00719 
00720   //string sDetectorType="C";
00721   string sDetector="";
00722   //string sPrefix="h";//default
00723   string sPrefix="";//default
00724   if (prefix!="") sPrefix+=prefix;
00725   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00726   string sFileName=sBase+".root";
00727   
00728   //test if file already exists
00729   ifstream Test(sFileName.c_str());
00730   
00731   //open the appropriate file
00732   if(!Test){
00733     outputFile=new TFile(sFileName.c_str(),"RECREATE");
00734   }
00735   else {
00736     //Need new filename
00737     Int_t fred=1;
00738     while(Test) {
00739       Test.close();
00740       string sAppendage=Form("%d",fred);
00741       sFileName=sBase+"_"+sAppendage+".root";
00742       Test.open(sFileName.c_str());
00743       fred++;
00744     }
00745     outputFile=new TFile(sFileName.c_str(),"NEW");
00746     outputFile->SetCompressionLevel(9);
00747   }
00748   
00749   string sTmp="No File!";
00750   if (outputFile) sTmp=outputFile->GetName();
00751 
00752   MSG("NuBase",Msg::kInfo) 
00753     <<"Output file opened: "<<sTmp<<endl;
00754   return outputFile;
00755 }

TFile * NuBase::OpenFileRECREATE ( std::string  sFileName  )  const

Definition at line 759 of file NuBase.cxx.

References Msg::kInfo, and MSG.

Referenced by NuDSTAna::DoIO().

00760 {
00761   //call this static function to ensure any histograms created
00762   //after the file is opened are added
00763   TH1::AddDirectory(true);
00764   
00765   //create the tfile pointer to be returned
00766   TFile* outputFile=0;
00767   
00768   outputFile=new TFile(sFileName.c_str(),"RECREATE");
00769   
00770   MSG("NuBase",Msg::kInfo) 
00771     <<"Output file opened: "<<outputFile->GetName()<<endl;
00772   return outputFile;
00773 }

void NuBase::OpenOutFile ( TString  outName,
TString  opt = "RECREATE" 
) [virtual]

Definition at line 185 of file NuBase.cxx.

References fOutFile, Msg::kError, and MSG.

00186 {
00187         TH1::AddDirectory(true);
00188   if (fOutFile) {
00189                 fOutFile->Close();
00190                 delete fOutFile;
00191         }
00192         fOutFile = new TFile(outName, opt);
00193         if (!fOutFile->IsOpen()) {
00194       MSG("NuBase",Msg::kError)<< "File " << outName << " did not open!"<<endl;         
00195         }
00196 }

ofstream * NuBase::OpenTxtFile ( const NuConfig config,
std::string  prefix 
) const

Definition at line 777 of file NuBase.cxx.

References NuConfig::detector, Form(), Detector::kCalDet, Detector::kFar, Msg::kInfo, SimFlag::kMC, Detector::kNear, MSG, NuConfig::run, and NuConfig::simFlag.

00779 {
00780   //create the tfile pointer to be returned
00781   ofstream* outputFile=0;
00782   
00783   //convert variables to string
00784   string sRunNumber=Form("%d",config.run);
00785   string sZeros="";
00786   if (config.run>=0 && config.run<10) sZeros="00000000";
00787   else if (config.run>=10 && config.run<100) sZeros="000000";
00788   else if (config.run>=100 && config.run<1000) sZeros="00000";
00789   else if (config.run>=1000 && config.run<10000) sZeros="0000";
00790   else if (config.run>=10000 && config.run<100000) sZeros="000";
00791   else if (config.run>=100000 && config.run<1000000) sZeros="00";
00792   else if (config.run>=1000000 && config.run<10000000) sZeros="0";
00793   else if (config.run>=10000000 && config.run<100000000) sZeros="";
00794   sRunNumber=sZeros+sRunNumber;
00795 
00796   string sDetector="UnknownDet";
00797   if (config.detector==Detector::kNear) {
00798     sDetector="N";
00799     if (config.simFlag==SimFlag::kMC) sDetector="n";
00800   }
00801   else if (config.detector==Detector::kFar) {
00802     sDetector="F";
00803     if (config.simFlag==SimFlag::kMC) sDetector="f";
00804   }
00805   else if (config.detector==Detector::kCalDet) {
00806     sDetector="C";
00807     if (config.simFlag==SimFlag::kMC) sDetector="c";
00808   }
00809   else cout<<"Ahhh, don't know detector="<<config.detector<<endl;
00810   
00811   string sPrefix="";//default
00812   string sAnaDir=".";
00813   if (prefix!="") sPrefix+=prefix;
00814   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00815   string sFileName=sBase+".txt";
00816 
00817   outputFile=new ofstream(sFileName.c_str());
00818   
00819   if (outputFile){
00820     MSG("NuBase",Msg::kInfo) 
00821       <<"Output txt file opened: "<<sFileName<<endl;
00822   }
00823   else{
00824     MSG("NuBase",Msg::kInfo)
00825       <<"Txt file NOT opened: "<<sFileName<<endl;
00826   }
00827 
00828   return outputFile;
00829 }

ofstream * NuBase::OpenTxtFile ( Int_t  runNumber,
std::string  prefix 
) const

Definition at line 833 of file NuBase.cxx.

References Form(), Msg::kInfo, and MSG.

Referenced by NuAnalysis::ChargeSeparationOneSnarl(), NuAnalysis::ChargeSignCut(), NuAnalysis::EnergySpect(), NuDSTAna::FDTestAna(), NuDSTAna::JeffsTestAna(), NuAnalysis::LIRejectionTest(), NuDSTAna::NDTestAna(), and NuDSTAna::StdCCAna().

00835 {
00836   //create the tfile pointer to be returned
00837   ofstream* outputFile=0;
00838   
00839   //convert variables to string
00840   string sRunNumber=Form("%d",runNumber);
00841   string sZeros="";
00842   if (runNumber>=0 && runNumber<10) sZeros="00000000";
00843   else if (runNumber>=10 && runNumber<100) sZeros="000000";
00844   else if (runNumber>=100 && runNumber<1000) sZeros="00000";
00845   else if (runNumber>=1000 && runNumber<10000) sZeros="0000";
00846   else if (runNumber>=10000 && runNumber<100000) sZeros="000";
00847   else if (runNumber>=100000 && runNumber<1000000) sZeros="00";
00848   else if (runNumber>=1000000 && runNumber<10000000) sZeros="0";
00849   else if (runNumber>=10000000 && runNumber<100000000) sZeros="";
00850   sRunNumber=sZeros+sRunNumber;
00851 
00852   string sDetectorType="Run";//was F
00853   string sPrefix="";//default
00854   string sAnaDir=".";
00855   if (prefix!="") sPrefix+=prefix;
00856   string sBase=sAnaDir+"/"+sPrefix+sDetectorType+sRunNumber;
00857   string sFileName=sBase+".txt";
00858 
00859   outputFile=new ofstream(sFileName.c_str());
00860   
00861   if (outputFile){
00862     MSG("NuBase",Msg::kInfo) 
00863       <<"Output txt file opened: "<<sFileName<<endl;
00864   }
00865   else{
00866     MSG("NuBase",Msg::kInfo)
00867       <<"Txt file NOT opened: "<<sFileName<<endl;
00868   }
00869 
00870   return outputFile;
00871 }

void NuBase::PrintLoopProgress ( Int_t  entry,
Float_t  nEntries,
Int_t  printMode 
) const [protected]

Definition at line 886 of file NuBase.cxx.

References Msg::kInfo, and MSG.

Referenced by NuDSTAna::MakeCuts(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDst2014(), NuDSTAna::MakeMicroDstNC2012(), and SetLoopVariables().

00888 {
00889   if (printMode==1){
00890     Float_t fract=ceil(nEntries/20.);  
00891     if (ceil(((Float_t)entry)/fract)==((Float_t)entry)/fract){
00892       MSG("STAnalysis",Msg::kInfo) 
00893         <<"Fraction of loop complete: "<<entry 
00894         <<"/"<<nEntries<<"  ("
00895         <<(Int_t)(100.*entry/nEntries)<<"%)"<<endl;
00896     }
00897   }
00898 }

void NuBase::SetLoopVariables ( Int_t  event,
Int_t  printMode = 1 
) [protected]

Definition at line 875 of file NuBase.cxx.

References fChain, fChainBD, fEntries, and PrintLoopProgress().

00876 {
00877   this->PrintLoopProgress(entry,fEntries,printMode);
00878   
00879   //get the snarl/entry
00880   fChain->GetEvent(entry);
00881   if (fChainBD) fChainBD->GetEvent(entry); 
00882 }

void NuBase::SetRootFileObjects (  )  [private]

Definition at line 545 of file NuBase.cxx.

References NtpStRecord::evthdr, fChain, fChainBD, fEntries, fEntriesBD, fRec, fRecBD, Msg::kDebug, Msg::kInfo, MSG, NtpSREventSummary::nslice, and NtpBDLiteRecord::tortgt.

Referenced by NuBase().

00546 {
00547   MSG("NuBase",Msg::kInfo)
00548     <<"Running the SetRootFileObjects method..."<<endl;
00549 
00550   //set up tree
00551   fChain->SetBranchAddress("NtpStRecord",&fRec);
00552   if (fChainBD) fChainBD->SetBranchAddress("NtpBDLiteRecord",&fRecBD);
00553   //fBDtortgt
00554     
00555   //set the number of events in the tree
00556   fEntries=static_cast<Int_t>(fChain->GetEntries());
00557   if (fChainBD) fEntriesBD=static_cast<Int_t>(fChainBD->GetEntries());
00558   MSG("NuBase",Msg::kInfo)
00559     <<"NtpSt tree has "<<fEntries<<" entries"<<endl;
00560   MSG("NuBase",Msg::kInfo)
00561     <<"NtpBDLite tree has "<<fEntriesBD<<" entries"<<endl;
00562     
00563   if (fEntries>0){
00564     //get the snarl/event
00565     fChain->GetEvent(0); 
00566     //MSG("NuBase",Msg::kInfo)
00567     //<<"First run number="<<fRec->fHeader.fRun<<endl;
00568     MSG("NuBase",Msg::kInfo)
00569       <<"SetRootFileObjects: first snarl nslice="
00570       <<fRec->evthdr.nslice<<endl;
00571   }
00572 
00573   if (fEntriesBD>0){
00574     //get the snarl/event
00575     fChainBD->GetEvent(0); 
00576     MSG("NuBase",Msg::kInfo)
00577       <<"First tortgt="<<fRecBD->tortgt<<" E12 POT"<<endl;
00578   }
00579   MSG("NuBase",Msg::kDebug)
00580     <<"Finished the SetRootFileObjects method"<<endl;
00581 }

void NuBase::Test (  ) 

Definition at line 911 of file NuBase.cxx.

References NtpSRFiducial::dr, NtpSRTrack::ds, NtpSRFiducial::dz, NtpSRTrack::end, NtpStRecord::evthdr, fChain, NtpSRTrack::fidend, fRec, Msg::kInfo, MSG, NtpSREventSummary::ndigit, NtpSRTrack::nstrip, NtpSREventSummary::ntrack, NtpSRStrip::plane, NtpSRTrack::range, NtpSRTrack::stp, NtpStRecord::stp, NtpSRTrack::stpz, NtpSRStrip::strip, NtpStRecord::trk, NtpSRTrack::vtx, and NtpSRVertex::z.

Referenced by OpenFile().

00912 {
00913   MSG("NuBase",Msg::kInfo) 
00914     <<" ** Running Test method... **"<<endl;
00915 
00919   
00920   //this->InitialiseLoopVariables();  
00921   
00922   //  for(Int_t event=0;event<fEntries;event++){
00923     
00924   //this->SetLoopVariables(event);
00925 
00926   for (int i=0;i<5;i++) {
00927     fChain->GetEntry(i);
00928     NtpStRecord& ntpst=(*fRec);   // Make a reference instead of a pointer
00929     
00930     TClonesArray& tcaTk=(*ntpst.trk);
00931     Int_t numTrks=tcaTk.GetEntries();
00932    
00933     MSG("NuBase",Msg::kInfo)
00934       <<"numTrks="<<numTrks
00935       <<", ndigit="<<fRec->evthdr.ndigit
00936       <<", nTrack="<<fRec->evthdr.ntrack<<endl;
00937 
00938     //Loop over tracks
00939     for (Int_t itrk=0;itrk<numTrks;itrk++){
00940       const NtpSRTrack* ptrk=
00941         dynamic_cast<NtpSRTrack*>(tcaTk[itrk]);
00942       const NtpSRTrack& trk=(*ptrk);
00943       cout<<"range="<<trk.range<<" nstrip="<<trk.nstrip<<" ds="<<trk.ds
00944           <<" fidend.dr,dz="<<trk.fidend.dr<<" "<<trk.fidend.dz<<" end-vtx.z:"
00945           <<trk.end.z-trk.vtx.z<<" "<<trk.stpz[1]-trk.stpz[0]<<endl;
00946 
00947 
00948       TClonesArray& tcaStp=(*ntpst.stp);
00949       Int_t numStps=tcaStp.GetEntries();
00950       MSG("NuBase",Msg::kInfo)
00951         <<"numStps="<<numStps<<endl;
00952       
00953       for (Int_t i=0;i<trk.nstrip;i++){
00954         
00955         //const NtpSRStrip* pstp=dynamic_cast<NtpSRStrip*>(tcaStp[i]);
00956         const NtpSRStrip* pstp=dynamic_cast<NtpSRStrip*>(tcaStp[trk.stp[i]]);
00957 
00958         const NtpSRStrip& stp=(*pstp);
00959         MSG("NuBase",Msg::kInfo)
00960           <<"Strip="<<stp.strip<<", pl="<<stp.plane
00961           <<", sigCor="<<stp.ph1.sigcor<<", tpos="<<stp.tpos<<endl;
00962       }
00963 
00964     }
00965 
00966 
00967     TClonesArray& tcaStp=(*ntpst.stp);
00968     Int_t numStps=tcaStp.GetEntries();
00969     MSG("NuBase",Msg::kInfo)
00970       <<endl<<"2nd: numStps="<<numStps<<endl;
00971     
00972     for (Int_t i=0;i<numStps;i++){      
00973       const NtpSRStrip* pstp=dynamic_cast<NtpSRStrip*>(tcaStp[i]);
00974       const NtpSRStrip& stp=(*pstp);
00975       MSG("NuBase",Msg::kInfo)
00976         <<"Strip="<<stp.strip<<", pl="<<stp.plane<<endl;
00977     }
00978     
00979     //    for (Int_t nsloop=0;nsloop<trk.nstrip;nsloop++) {
00981     //const NtpSRStrip* pstp=
00982     //dynamic_cast<NtpSRStrip*>(tcaStp[trk.stp[ns]]);
00983     //const NtpSRStrip& stp=(*pstp);
00984 
00985     //      if (stp.plane) ;   // Avoid compiler message ifndef PRINTLOTS
00986     //float du = trk.stpu[ns]-uprev;
00987     //float dv = trk.stpv[ns]-vprev;
00988     //float dz = trk.stpz[ns]-zprev;
00989     //cout<<" "<<ns<<" "<<du<<" "<<dv<<" "<<dz
00990     //    <<" uv:"<<trk.stpu[ns] <<" "<<trk.stpv[ns]
00991     //    <<" xyz:"<<trk.stpx[ns] <<" "<<trk.stpy[ns]<<" "<<trk.stpz[ns]
00992     //    <<" ds:"<<trk.stpds[ns]<<" stp: "<<trk.stp[ns]
00993     //    <<" "<<stp.plane<<endl;
00994     //  printf("%2d%8.4f%8.4f%8.4f%8.4f%2d uv:%8.4f%8.4f"
00995     //       " xyz:%8.4f%8.4f%8.4f%8.4f"
00996     //       " stp: %4d%4d\n"
00997     //       ,ns,du,dv,dz,stp.tpos,stp.planeview
00998     //       ,trk.stpu[ns],trk.stpv[ns]
00999     //       ,trk.stpx[ns],trk.stpy[ns],trk.stpz[ns]
01000     //       ,trk.stpds[ns],trk.stp[ns],stp.plane);
01001       
01002     //uprev = trk.stpu[ns];
01003     //vprev = trk.stpv[ns];
01004     //zprev = trk.stpz[ns];
01005     //}// stp loop
01006 
01007   }//end of for                                       
01008   
01012 
01013   MSG("NuBase",Msg::kInfo)<<"Finished main loop"<<endl;
01014 
01015   MSG("NuBase",Msg::kInfo) 
01016     <<" ** Finished Test method **"<<endl;
01017 }

void NuBase::TestEventLoop (  ) 

Definition at line 1021 of file NuBase.cxx.

References NtpStRecord::evt, fEntries, InitialiseLoopVariables(), Msg::kDebug, Msg::kInfo, MAXMSG, MSG, NtpSREvent::nshower, NtpSREvent::nstrip, NtpSRSlice::nstrip, NtpSREvent::ntrack, NtpSRStrip::ph0, NtpSRStrip::ph1, NtpSRPulseHeight::raw, NtpSREvent::shw, NtpStRecord::shw, NtpSREvent::slc, NtpStRecord::slc, NtpSREvent::stp, NtpSRSlice::stp, NtpStRecord::stp, NtpSREvent::trk, and NtpStRecord::trk.

01022 {
01023   MSG("NuBase",Msg::kInfo) 
01024     <<" ** Running TestEventLoop method... **"<<endl;
01025 
01029   
01030   this->InitialiseLoopVariables();  
01031   
01032   for(Int_t entry=0;entry<fEntries;entry++) {
01033   //for(Int_t entry=0;entry<5000;entry++) {
01034     
01035     this->SetLoopVariables(entry);
01036 
01037     NtpStRecord& ntp=(*fRec);
01038 
01039     TClonesArray& evtTca=(*ntp.evt);
01040     const Int_t numEvts=evtTca.GetEntriesFast();
01041     
01042     TClonesArray& trkTca=(*ntp.trk);
01043     const Int_t numTrks=trkTca.GetEntriesFast();
01044 
01045     TClonesArray& shwTca=(*ntp.shw);
01046     const Int_t numShws=shwTca.GetEntriesFast();
01047 
01048     TClonesArray& stpTca=(*ntp.stp);
01049     const Int_t numStps=stpTca.GetEntries();
01050 
01051     TClonesArray& slcTca=(*ntp.slc);
01052     const Int_t numSlcs=slcTca.GetEntries();
01053     
01054     Float_t totalSnarlAdc=0;
01055     Float_t totalEvtAdc=0;
01056     Float_t totalSlcAdc=0;
01057     Float_t thisSlcAdc=0;
01058     
01059     for (Int_t i=0;i<numStps;i++) {
01060       const NtpSRStrip* pstp=
01061         dynamic_cast<NtpSRStrip*>(stpTca[i]);
01062       const NtpSRStrip& stp=(*pstp);
01063       totalSnarlAdc+=stp.ph0.raw+stp.ph1.raw;
01064     }
01065     
01066     if (numEvts==0 && numTrks>0) {
01067       cout<<"Ahhh, num events in tca="<<numEvts
01068           <<", trks="<<numTrks<<endl;
01069     }
01070     
01071     if (numEvts>1) {
01072       MAXMSG("NuBase",Msg::kInfo,10)
01073         <<"High num evts="<<numEvts<<", trks="<<numTrks<<endl;
01074     }
01075 
01076     if (numSlcs!=1) {
01077       MAXMSG("NuBase",Msg::kInfo,10)
01078         <<"High num slices in tca="<<numSlcs
01079         <<", trks="<<numTrks<<endl;
01080       //continue;
01081     }
01082     
01083     MAXMSG("NuBase",Msg::kInfo,100)
01084       <<"Num events in tca="<<numEvts
01085       <<", slcs="<<numSlcs<<", trks="<<numTrks<<endl;
01086     
01087     Int_t slcStps=0;
01088     
01089     //loop over the slices
01090     for (Int_t islc=0;islc<numSlcs;++islc) {
01091       const NtpSRSlice* pslc=
01092         dynamic_cast<NtpSRSlice*>(slcTca[islc]);
01093       const NtpSRSlice& slc=(*pslc);
01094 
01095       MAXMSG("NuBase",Msg::kDebug,200)
01096         <<"  slice "<<islc+1<<" of "<<numSlcs<<endl;
01097       
01098       slcStps+=slc.nstrip;
01099 
01100       //loop over strips in slc
01101       for (Int_t i=0;i<slc.nstrip;++i) {
01102         const NtpSRStrip* pstp=
01103           dynamic_cast<NtpSRStrip*>(stpTca[slc.stp[i]]);
01104         const NtpSRStrip& stp=(*pstp);
01105         totalSlcAdc+=stp.ph0.raw+stp.ph1.raw;
01106       }
01107 
01108       //loop over tracks in slc  ---- can't do this!!!
01109       //for(int i=0;i<slc.ntrack;i++){    
01110       //const NtpSRTrack* ptrk=
01111       //  dynamic_cast<NtpSRTrack*>(trkTca[slc.trk[i]]);
01112       //const NtpSRTrack& trk=(*ptrk);
01113 
01114       //trkStps=trk.nstrip;
01115       //MAXMSG("NuBase",Msg::kInfo,300)
01116       //  <<"    track "<<i+1<<" of "<<slc.ntrack
01117       //  <<", trkStps="<<trkStps<<endl;
01118       //}
01119     }
01120 
01121     map<Int_t,Int_t> evtPerSlc;
01122     
01123     //loop over the events
01124     for (Int_t ntpevt=0;ntpevt<numEvts;++ntpevt) {
01125       const NtpSREvent* pevt=
01126         dynamic_cast<NtpSREvent*>(evtTca[ntpevt]);
01127       const NtpSREvent& evt=(*pevt);
01128       
01129       MAXMSG("NuBase",Msg::kInfo,100)
01130         <<"Entry "<<entry<<" has tracks="<<evt.ntrack
01131         <<", shws="<<numShws<<", slcs="<<numSlcs<<endl;
01132 
01133       //get the slice associated with this event
01134       const NtpSRSlice* pslc=
01135         dynamic_cast<NtpSRSlice*>(slcTca[evt.slc]);
01136       const NtpSRSlice& slc=(*pslc);
01137 
01138       evtPerSlc[evt.slc]++;
01139 
01140       //check that the filter works
01141       Int_t evts=-1;
01142       Bool_t goodEvt=true;
01143       if (goodEvt){
01144         MAXMSG("NuBase",Msg::kInfo,100)
01145           <<"TEST::entry="<<entry
01146           <<", evt="<<ntpevt<<" is good, evtsPerSlc="<<evts
01147           <<" (slc="<<evt.slc<<")"<<endl;
01148       }
01149       else{
01150         MAXMSG("NuBase",Msg::kInfo,100)
01151           <<"TEST::entry="<<entry
01152           <<", evt="<<ntpevt<<" is bad, evtsPerSlc="<<evts
01153           <<" (slc="<<evt.slc<<")"<<endl;
01154       }
01155       
01156       if (evt.ntrack!=1 || evt.nshower>1) continue;
01157 
01158       Int_t trkStps=0;
01159       Int_t shwStps=0;
01160       
01161       //loop over strips in slc
01162       for (Int_t i=0;i<slc.nstrip;++i) {
01163         const NtpSRStrip* pstp=
01164           dynamic_cast<NtpSRStrip*>(stpTca[slc.stp[i]]);
01165         const NtpSRStrip& stp=(*pstp);
01166         thisSlcAdc+=stp.ph0.raw+stp.ph1.raw;
01167       }
01168       
01169       //loop over tracks in evt
01170       for(int i=0;i<evt.ntrack;i++) {    
01171         const NtpSRTrack* ptrk=
01172           dynamic_cast<NtpSRTrack*>(trkTca[evt.trk[i]]);
01173         const NtpSRTrack& trk=(*ptrk);
01174 
01175         trkStps=trk.nstrip;
01176         
01177         for (Int_t i=0;i<trk.nstrip;i++) {
01178           const NtpSRStrip* pstp=
01179             dynamic_cast<NtpSRStrip*>(stpTca[trk.stp[i]]);
01180           const NtpSRStrip& stp=(*pstp);
01181             MAXMSG("NuBase",Msg::kDebug,100)
01182               <<"strip time="<<stp.time0<<endl;
01183         }
01184       }
01185 
01186       //loop over showers in evt
01187       for(int i=0;i<evt.nshower;i++) {    
01188         const NtpSRShower* pshw=
01189           dynamic_cast<NtpSRShower*>(shwTca[evt.shw[i]]);
01190         const NtpSRShower& shw=(*pshw);
01191         
01192         shwStps=shw.nstrip;
01193       }
01194 
01195       //loop over strips in evt
01196       for (Int_t i=0;i<evt.nstrip;i++) {
01197         const NtpSRStrip* pstp=
01198           dynamic_cast<NtpSRStrip*>(stpTca[evt.stp[i]]);
01199         const NtpSRStrip& stp=(*pstp);
01200         totalEvtAdc+=stp.ph0.raw+stp.ph1.raw;
01201       }
01202       MAXMSG("NuBase",Msg::kInfo,100)
01203         <<"e="<<entry<<", evt="<<ntpevt
01204         <<", ADCs: snl="<<totalSnarlAdc
01205         <<", evt="<<totalEvtAdc
01206         <<", slc="<<totalSlcAdc
01207         <<", tslc="<<thisSlcAdc
01208         <<", #st="<<numStps<<","<<evt.nstrip<<","<<slcStps
01209         //<<", trk="<<trkStps<<", shw="<<shwStps
01210         <<endl;
01211     }
01212 
01213     //make this into a function
01214     //Bool_t FilterMultiEvtPerSlc(ntp,slc,entry)
01215     typedef map<Int_t,Int_t>::const_iterator slcIt;
01216     MAXMSG("NuBase",Msg::kInfo,30)
01217       <<"MAIN::Events per slice for entry="<<entry<<endl;
01218     for (slcIt it=evtPerSlc.begin();it!=evtPerSlc.end();++it) {
01219       MAXMSG("NuBase",Msg::kInfo,200)
01220         <<"  slice "<<it->first<<" has "<<it->second<<" event(s)"<<endl;
01221     }
01222     
01223   }//end of for                                       
01224     
01228   
01229   MSG("NuBase",Msg::kInfo)<<"Finished main loop"<<endl;
01230 
01231   MSG("NuBase",Msg::kInfo) 
01232     <<" ** Finished TestEventLoop method **"<<endl;
01233 }

void NuBase::WriteOutHistos (  )  [virtual]

Definition at line 136 of file NuBase.cxx.

References fOutFile, GetNumFilesAddedToChain(), Msg::kInfo, Msg::kWarning, and MSG.

Referenced by NuAnalysis::EndJob().

00137 {
00138   //write out the histos to the file, if it's open
00139   if (fOutFile){
00140     if (fOutFile->IsWritable()) {
00141       fOutFile->cd();
00142 
00143       //store the number of files added to the chain      
00144       Int_t nf=this->GetNumFilesAddedToChain();
00145       TH1F* hNumFiles=new TH1F("hNumFiles","hNumFiles",15,-5,10);
00146       hNumFiles->Fill(1,nf);//store as weight, access with GetMaximum
00147 
00148       //get the run number to print it out below
00149       TH1F* hRun=dynamic_cast<TH1F*>(gROOT->FindObject("hRun"));
00150       Float_t nr=-1;
00151       if (hRun) nr=hRun->GetEntries();
00152       MSG("NuAnalysis",Msg::kInfo)
00153         <<"Files added to chain="<<hNumFiles->GetMaximum()
00154         <<", runs found="<<nr<<endl;
00155 
00156       //create a tree and set branches      
00157       //TTree runInfo("runInfo","runInfo");
00158       //have to create local variables here
00159       //I think it's something to do with the fact that they are
00160       //read in on other trees in this class as well???
00161       //No, actually not because fSigCorsPerMip is not in a tree
00162       //don't understand this crazyness!
00163       //Int_t lSimFlag=0;
00164       //runInfo.Branch("SimFlag",&lSimFlag,"SimFlag/I");
00165 
00166 
00167       //fill and write      
00168       //runInfo.Fill();
00169       //runInfo.Write();
00170 
00171       MSG("NuBase",Msg::kInfo)
00172         <<"Writing histos to: "<<fOutFile->GetName()<<" ..."<<endl;
00173       fOutFile->Write();
00174       //fOutFile->Close();//this makes histos disappear from canvases
00175       //so do it in the destructor (need to make NuBase on heap)
00176     }
00177     else {
00178       MSG("NuBase",Msg::kWarning)<<"File not writable!"<<endl;
00179     }
00180   }
00181 }


Member Data Documentation

TChain* NuBase::fChain [private]

Definition at line 85 of file NuBase.h.

Referenced by MakeChain(), NuBase(), SetLoopVariables(), SetRootFileObjects(), and Test().

TChain* NuBase::fChainBD [private]

Definition at line 86 of file NuBase.h.

Referenced by MakeChain(), NuBase(), SetLoopVariables(), and SetRootFileObjects().

Float_t NuBase::fEntries [private]

Definition at line 90 of file NuBase.h.

Referenced by GetEntries(), NuBase(), SetLoopVariables(), SetRootFileObjects(), and TestEventLoop().

Float_t NuBase::fEntriesBD [private]

Definition at line 91 of file NuBase.h.

Referenced by NuBase(), and SetRootFileObjects().

std::string NuBase::fFirstFileName [private]

Definition at line 97 of file NuBase.h.

Referenced by GetFirstFileName(), MakeChain(), and NuBase().

string NuBase::fInputFileName = "" [static, private]

Definition at line 82 of file NuBase.h.

Referenced by GetInputFileName(), and MakeFileList().

Bool_t NuBase::fLoadTrees = true [static, private]

Definition at line 83 of file NuBase.h.

Referenced by LoadTrees(), and NuBase().

Int_t NuBase::fNumFiles [private]

Definition at line 95 of file NuBase.h.

Referenced by GetNumFilesAddedToChain(), MakeChain(), and NuBase().

TFile* NuBase::fOutFile [protected]

Definition at line 59 of file NuBase.h.

Referenced by NuAnalysis::BasicPlots(), NuAnalysis::ChargeSignCut(), CloseOutFile(), NuAnalysis::CrossSections(), NuDSTAna::DoIO(), NuDSTAna::DoIOSimple(), NuAnalysis::Efficiencies(), NuAnalysis::EfficienciesOld(), NuAnalysis::EndJob(), NuAnalysis::EnergySpect(), NuAnalysis::EnergySpectMC(), NuDSTAna::FDTestAna(), GetOutputFile(), NuAnalysis::LIRejectionTest(), NuAnalysis::N_1(), NuDSTAna::NMBAna(), NuAnalysis::NMBSummaryTreeAna(), NuBase(), NuAnalysis::NuMuBarAppearance(), OpenOutFile(), WriteOutHistos(), and ~NuBase().

NtpStRecord* NuBase::fRec [private]

Definition at line 87 of file NuBase.h.

Referenced by GetNtpStRecord(), NuBase(), SetRootFileObjects(), and Test().

NtpBDLiteRecord* NuBase::fRecBD [private]

Definition at line 88 of file NuBase.h.

Referenced by GetNtpBDLiteRecord(), NuBase(), and SetRootFileObjects().

Int_t NuBase::fRun [private]

Definition at line 92 of file NuBase.h.

Referenced by NuBase().

std::string NuBase::fS [private]

Definition at line 98 of file NuBase.h.

Referenced by NuBase().

Int_t NuBase::fSubrun [private]

Definition at line 93 of file NuBase.h.

Referenced by NuBase().


The documentation for this class was generated from the following files:
Generated on Mon Sep 1 00:52:06 2014 for loon by  doxygen 1.4.7