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