Class Reference for E1039 Core & Analysis Software
merge_emb_file.cc
Go to the documentation of this file.
1 R__LOAD_LIBRARY(interface_main)
2 R__LOAD_LIBRARY(ana_embedding)
3 using namespace std;
4 
6 {
7  const int n_evt_file = 2000; // N of events per merged file
8  const string fn_list = "list_run_spill.txt";
9  const string dir_in = "scratch";
10 
11  string dir_out = (string)"/pnfs/e1039/scratch/users/"+gSystem->Getenv("USER")+"/HitEmbedding/data_emb_nim4_merged";
12  if (! gSystem->AccessPathName(dir_out.c_str())) {
13  cout << "The output directory exists. Enter 'GO' to delete it." << endl;
14  string input;
15  cin >> input;
16  if (input != "GO") {
17  cout << "Abort." << endl;
18  exit(0);
19  }
20  cout << "Deleting the directory..." << endl;
21  gSystem->Exec(("rm -rf "+dir_out).c_str());
22  }
23 
24  vector<int> list_run;
25  ifstream ifs(fn_list);
26  int run_id;
27  int spill_id;
28  while (ifs >> run_id >> spill_id) list_run.push_back(run_id);
29  ifs.close();
30  std::sort(list_run.begin(), list_run.end());
31  list_run.erase(std::unique(list_run.begin(), list_run.end()), list_run.end());
32  int n_run = list_run.size();
33  cout << "N of runs = " << n_run << endl;
34 
35  ostringstream oss;
36  int n_evt_ok = 0;
37  int n_evt_ng = 0;
38  int n_evt_now = 0;
39  int idx_out = 1;
40  TFile* file_out = 0;
41  TTree* tree_out = 0;
42  for (int i_run = 0; i_run < n_run; i_run++) {
43  run_id = list_run[i_run];
44  cout << "Run " << run_id << " | " << i_run << "/" << n_run << endl;
45  oss.str("");
46  oss << dir_in << "/run_" << setfill('0') << setw(6) << run_id << "/out/embedding_data.root";
47  string fn_in = oss.str();
48  TFile* file_in = new TFile(fn_in.c_str());
49  cout << " " << fn_in << endl;
50  if (! file_in->IsOpen()) {
51  cout << " Cannot open the input file." << endl;
52  delete file_in;
53  continue;
54  }
55  TTree* tree_in = (TTree*)file_in->Get("tree");
56  if (! tree_in) {
57  cout << " Cannot get the input tree." << endl;
58  delete file_in;
59  continue;
60  }
61  SQEvent* evt = 0;
62  SQHitVector* vec_hit = 0;
63  EmbQAData* qa_data = 0;
64  tree_in->SetBranchAddress("SQEvent" , &evt);
65  tree_in->SetBranchAddress("SQHitVector", &vec_hit);
66  tree_in->SetBranchAddress("qa_data" , &qa_data);
67  int n_ent = tree_in->GetEntries();
68  cout << " N of entries = " << n_ent << endl;
69  for (int i_ent = 0; i_ent < n_ent; i_ent++) {
70  tree_in->GetEntry(i_ent);
71  if (! file_out) {
72  cout << " Output file: idx = " << idx_out << endl;
73  oss.str("");
74  oss << dir_out << "/" << setw(4) << idx_out;
75  gSystem->mkdir(oss.str().c_str(), true);
76  oss << "/embedding_data.root";
77  file_out = new TFile(oss.str().c_str(), "RECREATE");
78  tree_out = new TTree("tree", "Created by merge_emb_file.cc.");
79  tree_out->Branch("SQEvent" , &evt);
80  tree_out->Branch("SQHitVector", &vec_hit);
81  }
82  if (qa_data->D1 == 0 || qa_data->D1 > 350 ||
83  qa_data->D2 == 0 || qa_data->D2 > 170 ||
84  qa_data->D3p == 0 || qa_data->D3p > 140 ||
85  qa_data->D3m == 0 || qa_data->D3m > 140 ) {
86  n_evt_ng++;
87  continue;
88  }
89  tree_out->Fill();
90  n_evt_ok++;
91  n_evt_now++;
92  if (n_evt_now == n_evt_file) {
93  //cout << " Close the output file." << endl;
94  file_out->Write();
95  file_out->Close();
96  file_out = 0;
97  idx_out++;
98  n_evt_now = 0;
99  }
100  }
101  file_in->Close();
102  }
103  if (file_out) {
104  file_out->Write();
105  file_out->Close();
106  file_out = 0;
107  }
108 
109  ofstream ofs(dir_out+"/00info.txt");
110  ofs << "n_evt_file = " << n_evt_file << "\n"
111  << "dir_in = " << dir_in << "\n"
112  << "dir_out = " << dir_out << "\n"
113  << "n_evt_ok = " << n_evt_ok << "\n"
114  << "n_evt_ng = " << n_evt_ng << "\n";
115  ofs.close();
116  exit(0);
117 }
An SQ interface class to hold one event header.
Definition: SQEvent.h:17
An SQ interface class to hold a list of SQHit objects.
Definition: SQHitVector.h:32
void merge_emb_file()
int D2
Definition: TreeData.h:89
int D1
Definition: TreeData.h:88
int D3m
Definition: TreeData.h:91
int D3p
Definition: TreeData.h:90