Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

FileLumper.cxx

Go to the documentation of this file.
00001 //==========================================================
00002 //
00003 // FileLumper.cxx
00004 //
00005 // Authors: Pedro Ochoa
00006 //
00007 // Written: December 21 2007
00008 //
00009 //===========================================================
00010 
00011 #include <iostream>
00012 #include <string>
00013 #include <sstream>
00014 
00015 #include "TSystem.h"
00016 #include "MCNNAnalysis/FileLumper.h"
00017 #include "MCNNAnalysis/NNReader.h"
00018 
00019 using namespace std;
00020 
00021 FileLumper::FileLumper(){
00022   
00023   OutputFile = new TFile();
00024   OutputTree = new TTree("nn","Minos NuE Analysis Results");
00025   nread = new NNReader("nn",true);
00026 
00027   cce = new MinosCompactEvent();
00028 
00029   mar = new MinosAnalysisResult();
00030   
00031 }
00032 
00033 FileLumper::FileLumper(const char* path_to_unmerged, const char* filename, Int_t pieces_in){
00034 
00035   cce = new MinosCompactEvent();
00036   mar = new MinosAnalysisResult();
00037   
00038   Bool_t catastrophe=false;
00039   nread = new NNReader("nn",true);
00040 
00041   //-->Putting input files in chain
00042   for(int ii=0;ii<pieces_in;++ii){
00043     
00044     //make file name
00045     ostringstream line;
00046     line << path_to_unmerged << "/mc*nn_" << ii << "_" << filename;
00047     string linestr = line.str();
00048     //NOTE: did mc*nn instead of mcnn just to add a wildcard in there. For some reason in 
00049     // root 05-16-00 TChain:Add always returns 1 if file is completely specified without
00050     // wildcards, even if file name is bogus
00051     
00052     //Adding to chain
00053     Int_t filenum = nread->Add(linestr.c_str());
00054     cout << "Adding " << linestr.c_str() << endl;
00055     if(filenum!=1){
00056       cout << "WARNING: Could not add " << linestr.c_str() << endl;
00057       cout << "-->Aborting; Will not write lumped file." << endl;
00058       catastrophe=true;
00059       break;
00060     }   
00061   }
00062 
00063   tot_entries=nread->GetEntries();
00064   cout << "Have " << tot_entries << " in big nread chain" << endl;
00065   
00066   if(catastrophe==false){
00067 
00068     ostringstream fileoutput;
00069     // hardcoding $MCNNTMP as a hack
00070     fileoutput << "$MCNNTMP/mcnn_" << filename;
00071     string fileoutputstr = gSystem->ExpandPathName((fileoutput.str()).c_str());
00072 
00073     OutputFile = new TFile(fileoutputstr.c_str(),"recreate");
00074     OutputTree = new TTree("nn","Minos NuE Analysis Results");
00075     OutputTree->SetDirectory(OutputFile);   
00076     
00077     SetBranches();
00078     
00079     //Saving to output tree
00080     Int_t srCtr=0;
00081     while(nread->GetEntry(srCtr)){
00082       ++srCtr;
00083             
00084       cce = nread->GetInputCCE();
00085       mar = nread->GetMinosAnalysisResult();
00086       
00087       OutputTree->Fill();
00088       
00089     }
00090     
00091     OutputTree->Write();
00092     OutputFile->Close();
00093 
00094   }//only writing file if all input files were present
00095   
00096 }
00097 
00098 FileLumper::~FileLumper(){
00099 
00100   delete OutputFile;
00101   delete nread;
00102   delete cce;
00103   delete mar;
00104 
00105 }
00106 
00107 //===================================================================
00108 void FileLumper::SetBranches(){
00109   
00110   OutputTree->Branch("cce","MinosCompactEvent",&cce);
00111   OutputTree->Branch("comparisonResults", "MinosAnalysisResult", &mar);
00112   OutputTree->Branch("run", &nread->run, "run/I");
00113   OutputTree->Branch("snarl", &nread->snarl, "snarl/I");
00114   OutputTree->Branch("evt", &nread->evt, "evt/I");
00115   OutputTree->Branch("nuid", &nread->nuid, "nuid/I");
00116   OutputTree->Branch("nuidnoosc",&nread->nuidnoosc,"nuidnoosc/I");
00117   OutputTree->Branch("action", &nread->action, "action/I");
00118   OutputTree->Branch("nue", &nread->nue, "nue/F");
00119   OutputTree->Branch("nuenoosc",&nread->nuenoosc,"nuenoosc/F");
00120   OutputTree->Branch("reco_nue",&nread->reco_nue,"reco_nue/F");
00121   OutputTree->Branch("y", &nread->y, "y/F");
00122   OutputTree->Branch("emfrac", &nread->emfrac, "emfrac/F");
00123   OutputTree->Branch("ires",&nread->ires,"ires/I");
00124   OutputTree->Branch("qtot", &nread->qtot, "qtot/F");
00125   OutputTree->Branch("vtxx", &nread->vtxx, "vtxx/F");
00126   OutputTree->Branch("vtxy", &nread->vtxy, "vtxy/F");
00127   OutputTree->Branch("vtxz", &nread->vtxz, "vtxz/F");
00128   OutputTree->Branch("vtxu", &nread->vtxu, "vtxu/F");
00129   OutputTree->Branch("vtxv", &nread->vtxv, "vtxv/F");
00130   OutputTree->Branch("tvtxx", &nread->tvtxx, "tvtxx/F");
00131   OutputTree->Branch("tvtxy", &nread->tvtxy, "tvtxy/F");
00132   OutputTree->Branch("tvtxz", &nread->tvtxz, "tvtxz/F");
00133   OutputTree->Branch("tptype",&nread->tptype,"tptype/I");
00134   OutputTree->Branch("tpx",&nread->tpx,"tpx/F");
00135   OutputTree->Branch("tpy",&nread->tpy,"tpy/F");
00136   OutputTree->Branch("tpz",&nread->tpz,"tpz/F");
00137   OutputTree->Branch("npln", &nread->npln, "npln/I");
00138   OutputTree->Branch("nstp", &nread->nstp, "nstp/I");
00139   OutputTree->Branch("nplnu", &nread->nplnu, "nplnu/I");
00140   OutputTree->Branch("nplnv", &nread->nplnv, "nplnv/I");          
00141   OutputTree->Branch("mcpresel",&nread->mcpresel,"mcpresel/I");
00142   OutputTree->Branch("datapresel",&nread->datapresel,"datapresel/I");
00143   OutputTree->Branch("nxtalk",&nread->nxtalk,"nxtalk/I");
00144   OutputTree->Branch("nxtalk_tagged",&nread->nxtalk_tagged,"nxtalk_tagged/I");
00145   OutputTree->Branch("nxtalk_mistagged",&nread->nxtalk_mistagged,"nxtalk_mistagged/I"); 
00146   OutputTree->Branch("nphysics",&nread->nphysics,"nphysics/I");
00147   OutputTree->Branch("w2",&nread->w2,"w2/F");
00148   OutputTree->Branch("totpt",&nread->totpt,"totpt/F");
00149   OutputTree->Branch("snarl_pot",&nread->snarl_pot,"snarl_pot/F");
00150   OutputTree->Branch("good_snarl",&nread->good_snarl,"good_snarl/I");
00151   OutputTree->SetDirectory(OutputFile);
00152 
00153 }

Generated on Mon Feb 15 11:06:41 2010 for loon by  doxygen 1.3.9.1