CbmRoot
L1AlgoInputData.cxx
Go to the documentation of this file.
1 #include "L1AlgoInputData.h"
2 
3 #include <cstring>
4 #include <iostream>
5 using namespace std;
6 using std::ios;
7 /*
8 L1AlgoInputData::L1AlgoInputData( const L1AlgoInputData& a)
9 {
10  SetData( a.GetStsHits(), a.GetStsStrips(), a.GetStsStripsB(), a.GetStsZPos(),
11  a.GetSFlag(), a.GetSFlagB(), a.GetStsHitsStartIndex(), a.GetStsHitsStopIndex());
12 }
13 
14 
15 const L1AlgoInputData& L1AlgoInputData::operator=( const L1AlgoInputData& a)
16 {
17  SetData( a.GetStsHits(), a.GetStsStrips(), a.GetStsStripsB(), a.GetStsZPos(),
18  a.GetSFlag(), a.GetSFlagB(), a.GetStsHitsStartIndex(), a.GetStsHitsStopIndex());
19  return a;
20 }
21 
22 
23 void L1AlgoInputData::SetData( const vector< L1StsHit > & StsHits_,
24  const vector< L1Strip > & StsStrips_,
25  const vector< L1Strip > & StsStripsB_,
26  const vector< fscal > & StsZPos_,
27  const vector< unsigned char > & SFlag_,
28  const vector< unsigned char > & SFlagB_,
29  const THitI* StsHitsStartIndex_,
30  const THitI* StsHitsStopIndex_ )
31 {
32  vStsHits.resize(StsHits_.size());
33  vStsStrips.resize(StsStrips_.size());
34  vStsStripsB.resize(StsStripsB_.size());
35  vStsZPos.resize(StsZPos_.size());
36  vSFlag.resize(SFlag_.size());
37  vSFlagB.resize(SFlagB_.size());
38 
39  for(unsigned int i=0; i<StsHits_.size(); ++i ) {vStsHits[i] = StsHits_[i];
40 
41 }
42  for(unsigned int i=0; i<StsStrips_.size(); ++i ) vStsStrips[i] = StsStrips_[i];
43  for(unsigned int i=0; i<StsStripsB_.size(); ++i ) vStsStripsB[i] = StsStripsB_[i];
44  for(unsigned int i=0; i<StsZPos_.size(); ++i ) vStsZPos[i] = StsZPos_[i];
45  for(unsigned int i=0; i<SFlag_.size(); ++i ) vSFlag[i] = SFlag_[i];
46  for(unsigned int i=0; i<SFlagB_.size(); ++i ) vSFlagB[i] = SFlagB_[i];
47 
48  for(unsigned int i=0; i<MaxNStations+1; ++i) StsHitsStartIndex[i] = StsHitsStartIndex_[i];
49 
50  for(unsigned int i=0; i<MaxNStations+1; ++i) StsHitsStopIndex[i] = StsHitsStopIndex_[i];
51 }
52 
53 */
54 
55 istream& L1AlgoInputData::eatwhite(istream& is) // skip spaces
56 {
57  char c;
58  while (is.get(c)) {
59  if (isspace(c) == 0) {
60  is.putback(c);
61  break;
62  }
63  }
64  return is;
65 }
66 
67 bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
68  const int maxNEvent,
69  const int iVerbose) {
70  static int nEvent = 1;
71  static ifstream fadata;
72  static char fname[100];
73 
74  if (nEvent == 1) {
75  strcpy(fname, work_dir);
76  strcat(fname, "data_algo.txt");
77  fadata.open(fname);
78  }
79  if (!fadata.is_open()) return 0;
80 
81  if (nEvent <= maxNEvent) {
82 
83  vStsHits.clear();
84  vStsStrips.clear();
85  vStsStripsB.clear();
86  vStsZPos.clear();
87  vSFlag.clear();
88  vSFlagB.clear();
89 
90  // check correct position in file
91  char s[] = "Event: ";
92  int nEv;
93  fadata >> s;
94  // cout << s<< " s"<<endl;
95  fadata >> nEv;
96  // cout << nEv<< " nEv"<<endl;
97 
98  if (nEv != nEvent)
99  cout << "-E- CbmL1: Can't read event number " << nEvent << " from file "
100  << fname << endl;
101 
102  int n; // number of elements
103  // read algo->vStsStrips
104  fadata >> n;
105  // cout << n<< " vStsStrips"<<endl;
106  for (int i = 0; i < n; i++) {
107  fscal element;
108  unsigned short int element2 = 0;
109  fadata >> element;
110  vStsStrips.push_back(L1Strip(element, element2));
111  // fadata >> element;
112  // vStsStrips.push_back(L1Strip(element));
113  }
114  if (iVerbose >= 4)
115  cout << "vStsStrips[" << n << "]"
116  << " have been read." << endl;
117  // read algo->vStsStripsB
118  fadata >> n;
119  // cout << n<< " vStsStripsB"<<endl;
120  for (int i = 0; i < n; i++) {
121  fscal element;
122  unsigned short int element2 = 0;
123  fadata >> element;
124  vStsStripsB.push_back(L1Strip(element, element2));
125  // fadata >> element;
126  // vStsStripsB.push_back(L1Strip(element));
127  }
128  if (iVerbose >= 4)
129  cout << "vStsStripsB[" << n << "]"
130  << " have been read." << endl;
131  // read algo->vStsZPos
132  fadata >> n;
133  // cout << n<< " vStsZPos"<<endl;
134  for (int i = 0; i < n; i++) {
135  fscal element;
136  fadata >> element;
137  vStsZPos.push_back(element);
138  }
139  if (iVerbose >= 4)
140  cout << "vStsZPos[" << n << "]"
141  << " have been read." << endl;
142  // read algo->vSFlag
143  fadata >> n;
144  // cout << n<< " vSFlagB"<<endl;
145  for (int i = 0; i < n; i++) {
146  int element;
147  fadata >> element;
148  vSFlag.push_back(static_cast<unsigned char>(element));
149  }
150  if (iVerbose >= 4)
151  cout << "vSFlag[" << n << "]"
152  << " have been read." << endl;
153  // read algo->vSFlagB
154  fadata >> n;
155  // cout << n<< " vSFlagB"<<endl;
156  for (int i = 0; i < n; i++) {
157  int element;
158  fadata >> element;
159  vSFlagB.push_back(static_cast<unsigned char>(element));
160  }
161  if (iVerbose >= 4)
162  cout << "vSFlagB[" << n << "]"
163  << " have been read." << endl;
164  // read algo->vStsHits
165  fadata >> n;
166  // cout << n<< " vStsHits"<<endl;
167  int element_f; // for convert
168  int element_b;
169  int element_n;
170  int element_iz;
171  float element_time;
172  for (int i = 0; i < n; i++) {
173  L1StsHit element;
174  fadata >> element_f >> element_b >> element_n >> element_iz
175  >> element_time;
176  element.f = static_cast<THitI>(element_f);
177  element.b = static_cast<THitI>(element_b);
178 #ifdef USE_EVENT_NUMBER
179  element.n = static_cast<unsigned short int>(element_n);
180 #endif
181  element.iz = static_cast<TZPosI>(element_iz);
182  element.t_reco = element_time;
183  vStsHits.push_back(element);
184  }
185  if (iVerbose >= 4)
186  cout << "vStsHits[" << n << "]"
187  << " have been read." << endl;
188  // read StsHitsStartIndex and StsHitsStopIndex
189  n = 20;
190  for (int i = 0; i < n; i++) {
191  int tmp;
192  fadata >> tmp;
193  if (MaxNStations + 1 > i) StsHitsStartIndex[i] = tmp;
194  // cout << " StsHitsStartIndex[i]"<< StsHitsStartIndex[i] << endl;
195 
196  // cout << tmp<< " tmp"<<endl;
197  }
198  for (int i = 0; i < n; i++) {
199  int tmp;
200  fadata >> tmp;
201  if (MaxNStations + 1 > i) StsHitsStopIndex[i] = tmp;
202  // cout << " StsHitsStopIndex[i]"<< StsHitsStopIndex[i] << endl;
203  // cout << tmp<< " tmp"<<endl;
204  }
205 
206  if (iVerbose >= 2)
207  cout << "-I- CbmL1: CATrackFinder data for event " << nEvent
208  << " has been read from file " << fname << " successfully." << endl;
209  // if (nEvent == maxNEvent) fadata.close();
210  }
211  nEvent++;
212  return 1;
213 } // void L1AlgoInputData::ReadStAPAlgoData()
214 
215 /*
216 void L1AlgoInputData::PrintHits()
217 {
218  std::cout << "Event: " << std::endl;
219 
220  int n = vStsStrips.size(); // number of elements
221  std::cout << n << std::endl;
222  for (int i = 0; i < n; i++){
223  std::cout << vStsStrips[i] << std::endl;
224  }
225 
226  n = vStsStripsB.size();
227  std::cout << n << std::endl;
228  for (int i = 0; i < n; i++){
229  std::cout << vStsStripsB[i] << std::endl;
230  }
231 
232  n = vStsZPos.size();
233  std::cout << n << std::endl;
234  for (int i = 0; i < n; i++){
235  std::cout << vStsZPos[i] << std::endl;
236  }
237 
238  n = vSFlag.size();
239  std::cout << n << std::endl;
240  for (int i = 0; i < n; i++){
241  std::cout << static_cast<int>(vSFlag[i]) << std::endl;
242  }
243 
244  n = vSFlagB.size();
245  std::cout << n << std::endl;
246  for (int i = 0; i < n; i++){
247  std::cout << static_cast<int>(vSFlagB[i]) << std::endl;
248  }
249 
250  n = vStsHits.size();
251  std::cout << n << std::endl;
252  for (int i = 0; i < n; i++){
253  std::cout << static_cast<int>(vStsHits[i].f) << " ";
254  std::cout << static_cast<int>(vStsHits[i].b) << " ";
255  std::cout << static_cast<int>(vStsHits[i].iz) << std::endl;
256  }
257 
258  n = 20;
259  for (int i = 0; i < n; i++){
260  if (MaxNStations+1 > i) std::cout << StsHitsStartIndex[i] <<std::endl;
261  else std::cout << "0" <<std::endl;
262  }
263  for (int i = 0; i < n; i++){
264  if (MaxNStations+1 > i) std::cout << StsHitsStopIndex[i] <<std::endl;
265  else std::cout << "0" <<std::endl;
266  }
267 
268 } // void L1AlgoInputData::ReadStAPAlgoData()
269 
270 */
fscal
float fscal
Definition: L1/vectors/P4_F32vec4.h:250
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
L1StsHit
Definition: L1StsHit.h:12
TZPosI
unsigned short int TZPosI
Definition: L1StsHit.h:9
L1StsHit::b
TStripI b
Definition: L1StsHit.h:15
L1Strip
Definition: L1Strip.h:12
L1AlgoInputData::ReadHitsFromFile
bool ReadHitsFromFile(const char work_dir[100], const int maxNEvent, const int iVerbose)
Definition: L1AlgoInputData.cxx:67
THitI
unsigned int THitI
Definition: L1StsHit.h:8
L1AlgoInputData::eatwhite
static istream & eatwhite(istream &is)
Definition: L1AlgoInputData.cxx:55
MaxNStations
const int MaxNStations
Definition: L1AlgoEfficiencyPerformance.h:24
L1StsHit::t_reco
float t_reco
Definition: L1StsHit.h:17
L1AlgoInputData.h
L1StsHit::f
TStripI f
Definition: L1StsHit.h:15
L1StsHit::iz
TZPosI iz
Definition: L1StsHit.h:24