#include int TPOL_allruns(std::string indir = "", Bool_t debug = false){ if(indir==""){ cout << "TPOL_allruns:" << endl; cout << "Usage: " << endl; cout << "root TPOL_allruns.C(\"[input directory]\")" << endl; cout << "(example : /work/halld/data_monitoring/RunPeriod-2015-03/ver06/rootfiles/)" << endl; abort(); } char command[400]; // This command will show all ROOT files within the input directory, // then try to remove files that have KB size sprintf(command,"ls -lh %s/*.root | grep -v '[0-9]K ' | gawk '{print $9}' > ___filelist.txt",indir.c_str()); system(command); if(debug){ cout << "---------------------------------------------------------------------" << endl; system("cat ___filelist.txt"); cout << "---------------------------------------------------------------------" << endl; } ifstream IN("___filelist.txt"); std::string filename; TFile *infile; TH1I *tpol_num_events; TH1I *tpol_hitMultiplicity; TFile *outfile = new TFile("allruns.root","RECREATE"); // Graph to keep track of how many TPOL hit events there were TGraph *gtpol_num_events = new TGraph(); gtpol_num_events->SetName("gtpol_num_events"); TGraphErrors *gtpol_hitMultiplicity = new TGraphErrors(); gtpol_hitMultiplicity->SetName("gtpol_hitMultiplicity"); ofstream OUT("allruns.txt"); /////////////////////////////////// // Start of loop over files // /////////////////////////////////// while(IN >> filename){ if(debug) cout << "filename = " << filename << endl; infile = new TFile(filename.c_str()); tpol_num_events = (TH1I*)infile->Get("TPOL/tpol_num_events")->Clone("tpol_num_events"); tpol_hitMultiplicity = (TH1I*)infile->Get("TPOL/tpol_hitMultiplicity")->Clone("tpol_hitMultiplicity"); if(!tpol_num_events){ cout << "histogram tpol_num_events does not exist for file" << endl << filename << endl; abort(); } if(!tpol_hitMultiplicity){ cout << "histogram tpol_hitMultiplicity does not exist for file" << endl << filename << endl; abort(); } if(debug){ cout << "tpol_num_events->GetBinContent(1) = " << tpol_num_events->GetBinContent(1) << endl; cout << "tpol_hitMultiplicity->GetRMS() = " << tpol_hitMultiplicity->GetRMS() << endl; } // Get file number. Assume that input is results of offline monitoring, // so that the file name is of the form hd_root_00RRRRroot size_t pos = filename.find("hd_root_"); std::string runstring; Int_t run = -999; if(pos==std::string::npos){ cout << "substring hd_root not found in filename" << endl; cout << "aborting..." << endl; abort(); }else{ runstring = filename.substr(pos+8,6); if(debug) cout << runstring << endl; run = atoi(runstring.c_str()); } if(debug) cout << "run = " << setw(6) << setfill('0') << run << endl; // Fill graph with run number and number of TPOL hits if(debug) cout << "number of points so far = " << gtpol_num_events->GetN() << endl; gtpol_num_events->SetPoint(gtpol_num_events->GetN(),run,tpol_num_events->GetBinContent(1)); gtpol_hitMultiplicity->SetPoint(gtpol_hitMultiplicity->GetN(),run,tpol_hitMultiplicity->GetMean()); gtpol_hitMultiplicity->SetPointError(gtpol_hitMultiplicity->GetN()-1,0,tpol_hitMultiplicity->GetRMS()); // Spit out to text file OUT << setw(6) << setfill('0') << run << " " << setw(12) << setfill(' ') << tpol_num_events->GetBinContent(1) << setw(12) << setfill(' ') << tpol_hitMultiplicity->GetMean() << setw(12) << setfill(' ') << tpol_hitMultiplicity->GetRMS() << endl; infile = 0; tpol_num_events = 0; } // end of loop over files TCanvas *c1 = new TCanvas("c1","TPOL hit numbers",1800,1200); c1->SetLeftMargin(0.12); c1->SetRightMargin(0.03); c1->SetTopMargin(0.05); c1->SetBottomMargin(0.12); gtpol_num_events->SetTitle(""); gtpol_num_events->GetXaxis()->SetTitle("run number"); gtpol_num_events->GetXaxis()->CenterTitle(); gtpol_num_events->GetXaxis()->SetTitleFont(132); gtpol_num_events->GetXaxis()->SetTitleSize(0.060); gtpol_num_events->GetXaxis()->SetLabelFont(132); gtpol_num_events->GetXaxis()->SetLabelSize(0.050); gtpol_num_events->GetYaxis()->SetTitle("TPOL hits"); gtpol_num_events->GetYaxis()->CenterTitle(); gtpol_num_events->GetYaxis()->SetTitleFont(132); gtpol_num_events->GetYaxis()->SetTitleSize(0.060); gtpol_num_events->GetYaxis()->SetLabelFont(132); gtpol_num_events->GetYaxis()->SetLabelSize(0.050); gtpol_num_events->SetMarkerColor(kRed); gtpol_num_events->SetMarkerSize(0.8); gtpol_num_events->SetMarkerStyle(20); gtpol_num_events->SetLineColor(kRed); gtpol_num_events->SetLineWidth(1); gtpol_num_events->SetLineStyle(1); gtpol_num_events->GetXaxis()->SetLimits(2920,3305); gtpol_num_events->SetMinimum(0); gtpol_num_events->Draw("ALP"); c1->SaveAs("allruns.pdf"); c1->SetLogy(1); gtpol_num_events->SetMinimum(0.5); gtpol_num_events->Draw("ALP"); c1->SaveAs("allruns_log.pdf"); outfile->cd(); gtpol_num_events->Write(); gtpol_hitMultiplicity->Write(); outfile->Write(); }