Belle II Software  release-05-01-25
TRGCDCHoughMapConverter.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : TRGCDCHoughMapConverter.cc
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : This program is not completed.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRG_SHORT_NAMES
15 
16 #include <iostream>
17 #include <fstream>
18 #include <string>
19 #include <vector>
20 #include "trg/trg/Utilities.h"
21 
22 using namespace std;
23 using namespace Belle2;
24 
25 #define DEBUG_LEVEL 0
26 #define NAME "TRGCDCHoughMapConverter"
27 #define VERSION "version 0.00[2015/07/23]"
28 
29 int
30 main(int argc, char* argv[])
31 {
32 
33  cout << NAME << " ... " << VERSION << endl;
34  const string tab = " ";
35 
36  //...Check arguments...
37  if (argc != 3) {
38  cout << NAME << " !!! two arguments necessary" << endl
39  << tab << " 1 : input mapping file name" << endl
40  << tab << " 2 : output mapping file name" << endl;
41  return -1;
42  }
43 
44  //...Date...
45  string ts0 = TRGUtil::dateStringF();
46  // string ts1 = TRGUtil::dateString();
47 
48  //...1st argument : input Hough mapping file name...
49  const string iname = argv[1];
50 
51  //...2nd argument : output Hough mapping file name
52  const string oname = argv[2];
53 
54  cout << " input mapping file : " << iname << endl;
55  cout << " output mapping file : " << oname << endl;
56 
57  //...Open input file...
58  ifstream ifile(iname.c_str(), ios::in);
59  if (ifile.fail()) {
60  cout << NAME << " !!! can not open file" << endl
61  << " " << iname << endl;
62  return -2;
63  }
64 
65  //...Open output file...
66  ofstream ofile(oname.c_str(), ios::out);
67  if (ofile.fail()) {
68  cout << NAME << " !!! can not open file" << endl
69  << " " << oname << endl;
70  return -3;
71  }
72 
73  //...Read configuration data
74  char b[800];
75  vector<unsigned> tsf2h[9][400]; // [super layer][local id]
76  while (! ifile.eof()) {
77  ifile.getline(b, 800);
78  string l(b);
79 
80  if (b[0] == '#') continue;
81 
82  const unsigned hx = stoi(TRGUtil::carstring(l));
83  l = TRGUtil::cdrstring(l);
84  const unsigned hy = stoi(TRGUtil::carstring(l));
85  l = TRGUtil::cdrstring(l);
86 
87  const unsigned hcid = hy * 1000 + hx;
88 
89  while (1) {
90  const unsigned tsl = stoi(TRGUtil::carstring(l));
91  l = TRGUtil::cdrstring(l);
92  const unsigned tsi = stoi(TRGUtil::carstring(l));
93  l = TRGUtil::cdrstring(l);
94  tsf2h[tsl][tsi].push_back(hcid);
95 
96  if (l.size() == 0) break;
97  }
98  }
99 
100  //...Make a mirror image...
101  // vector<unsigned> tsf2hm[9][400]; // [super layer][local id]
102  for (unsigned tsl = 0; tsl < 9; tsl += 2) {
103  for (unsigned tsi = 0; tsi < 400; tsi++) {
104 
105  if (tsf2h[tsl][tsi].size() == 0) continue;
106 
107  //...Find y min...
108  unsigned miny = 25;
109  for (unsigned k = 0; k < tsf2h[tsl][tsi].size(); k++) {
110  const unsigned hcid = tsf2h[tsl][tsi][k];
111  const unsigned y = hcid / 1000;
112  if (y < miny) miny = y;
113  }
114 
115  //...Find x values...
116 
117  cout << "tsf " << tsl << " " << tsi << " x=";
118 
119  for (unsigned k = 0; k < tsf2h[tsl][tsi].size(); k++) {
120  const unsigned hcid = tsf2h[tsl][tsi][k];
121  const unsigned y = hcid / 1000;
122  if (y != miny) continue;
123  const unsigned x = hcid % 1000;
124  cout << " " << x;
125  }
126  cout << endl;
127  }
128  }
129 
130 
131  //...Output...
132  ofile << "# This file is generated by " << NAME << "[" << VERSION << "]"
133  << endl;
134  ofile << "# Source file is " << iname << endl;
135  ofile << "# " << ts0 << endl;
136  ofile << "#" << endl;
137  for (unsigned j = 1; j < 17; j++) {
138  for (unsigned i = 0; i < 160; i++) {
139  const unsigned hcid = j * 1000 + i;
140  ofile << i << " " << j;
141 
142  for (unsigned tsl = 0; tsl < 9; tsl += 2) {
143  for (unsigned tsi = 0; tsi < 400; tsi++) {
144  for (unsigned k = 0; k < tsf2h[tsl][tsi].size(); k++) {
145  if (tsf2h[tsl][tsi][k] == hcid)
146  ofile << " " << tsl << " " << tsi;
147  }
148  }
149  }
150  ofile << endl;
151  }
152  }
153 
154  return 0;
155 }
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19