/*********************************************************************** * * 2015/02/12 Kei Moriya * * Main file that calls selectors created from KsHunt tree. * ***********************************************************************/ #include #include #include #include #include #include #include #include "unistd.h" // to use optarg #include // ROOT header files #include "TROOT.h" #include "TFile.h" #include "TH1F.h" #include "TH2F.h" #include "TProfile.h" #include "TTree.h" #include "TMath.h" #include "TLatex.h" #include "TLine.h" #include "TLegend.h" #include "TPaveText.h" #include "TCanvas.h" #include "TPad.h" #include "TLorentzVector.h" #include "TProfile.h" #include "TGraphErrors.h" #include "TGraph2DErrors.h" #include "TString.h" #include "KsHunt_selector.h" // #include "KsHunt_Thrown_selector.h" // GlueX, my header files #include "particleType.h" #include "GlueX.h" #include "rootStyles.h" using namespace std; int main(int argc, char **argv){ setMyStyle(); gStyle->SetPadRightMargin(0.11); string infilename = ""; string infilelist = ""; string outfilename = ""; Bool_t infile_specified = false; Bool_t infilelist_specified = false; Int_t reconType = 1; char *progName = argv[0]; extern char* optarg; // Check command line arguments int c; while((c = getopt(argc,argv,"hi:l:o:")) != -1){ switch(c){ case 'h': cout << "analyze_KsHunt: " << endl; cout << "Options:" << endl; cout << "\t-i infile" << endl; cout << "\t-l infile list" << endl; cout << "\t-o outfile" << endl; exit(-1); break; case 'i': // Specify infile name. infilename = optarg; cout << "infile name: " << infilename << endl; infile_specified = true; break; case 'l': // Specify infile name. infilelist = optarg; cout << "infile list name: " << infilelist << endl; infilelist_specified = true; break; case 'o': // Specify outfile name. outfilename = optarg; cout << "outfile name: " << outfilename << endl; break; default: break; } } //___________________________________________________________________________________________ if(infile_specified==false && infilelist_specified==false){ cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; cout << "analyze_KsHunt" << endl; cout << "Must specify infile or infile list with options -i -l" << endl; cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; abort(); } if(infile_specified==true && infilelist_specified==true){ cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; cout << "analyze_KsHunt" << endl; cout << "Must specify ONLY infile or infile list with options -i -l" << endl; cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; abort(); } if(outfilename==""){ cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; cout << "analyze_KsHunt" << endl; cout << "Must specify outfile with option -o" << endl; cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; abort(); } Int_t NFILES = 1; char command[200]; if(infilelist_specified==true){ sprintf(command,"wc -l %s > nfiles.txt",infilelist.c_str()); system(command); ifstream IN_nfiles("nfiles.txt"); IN_nfiles >> NFILES; system("rm -f nfiles.txt"); } TFile *outfile = new TFile(outfilename.c_str(),"RECREATE"); outfile->Write(); ifstream IN_infilelist; if(infilelist_specified==true) IN_infilelist.open(infilelist.c_str()); //////////////////////////////////////////////// // // // Start of loop over files. // // // //////////////////////////////////////////////// Int_t nTotal = 0; for(Int_t nfile=0;nfile> infilename; infile = new TFile(infilename.c_str()); if(!infile){ cout << "infile " << infilename << " not found..." << endl; abort(); } cout << "processing file " << infilename << " (" << setw(3) << nfile+1 << "/" << setw(3) << NFILES << ")" << endl; } // Process recon trees -------------------------------------------------------------------------------------- string reconTreeName = "KsHunt_Tree"; TTree *intree_recon = (TTree*)infile->Get(reconTreeName.c_str()); KsHunt_selector *reconTreeSelector = new KsHunt_selector(intree_recon); stringstream ss; ss << outfilename; reconTreeSelector->SetOption(ss.str().c_str()); reconTreeSelector->Init(intree_recon); reconTreeSelector->Begin(intree_recon); for(Long64_t i=0;iGetEntries();i++){ reconTreeSelector->Process(i); } reconTreeSelector->Terminate(); // End of processing recon trees ---------------------------------------------------------------------------- /* // Process thrown trees ------------------------------------------------------------------------------------- TTree *intree_thrown = (TTree*)infile->Get("Thrown_Tree"); KsHunt_Thrown_selector *reconTreeSelector_thrown = new KsHunt_Thrown_selector(intree_thrown); reconTreeSelector_thrown->Init(intree_thrown); reconTreeSelector_thrown->Begin(intree_thrown); for(Long64_t i=0;iGetEntries();i++){ reconTreeSelector_thrown->Process(i); } reconTreeSelector_thrown->Terminate(); // End of processing thrown trees -------------------------------------------------------------------- */ } // end of loop over files outfile->Write(); //________________________________________________________________________________________________________________ return 0; }