// Interface for L1Algo #include "L1AlgoInter.h" #include "L1Algo/L1Algo.h" #include #include using namespace std; /// init members and read geometry from file. /// @param _maxNEvent - number of all analyse event /// @param _work_dir - first part of path in witch read and write files (data_perfo.txt, data_algo.txt, geo_algo.txt) /// @param _iVerbose - level of detailed of info void L1AlgoInter::Init(int _maxNEvent, const char* _work_dir, int _iVerbose) { if (_iVerbose >= 1) cout << " -I- run L1AlgoInter::Init(...)" << endl; // if( !fInstance ) fInstance = this; maxNEvent = _maxNEvent; nEvent = 1; strcpy (work_dir,_work_dir); iVerbose = _iVerbose; // cout << 0 << endl; // L1Algo *algo = new L1Algo(); // cout << 1 << endl; // read geo-array from file. For structure of array see CbmL1::Init() fscal geo[10000]; // buffer for read geo data int size; ReadStAPGeoData( (void*) geo, size); algo.Init(geo); // cout << " void L1AlgoInter::Init(int _maxNEvent, const char* _work_dir, int _iVerbose) done " << endl; } void L1AlgoInter::RunEv() { static double repeatTime = 0; // cout << "ai1" << endl; // const int NMergeEvents = 2; // collect N events into 1. ReadStAPAlgoData(); // L1Algo algo_tmp = algo; // for ( int iEv = 1; iEv < NMergeEvents; iEv++ ){ // const int stSize = algo_tmp.vStsStrips.size(); // const int stBSize = algo_tmp.vStsStripsB.size(); // ReadStAPAlgoData(); // // for (int i = 0; i < algo.vStsStrips.size(); i++){ // algo_tmp.vStsStrips.push_back(L1Strip(algo.vStsStrips[i], iEv)); // } // for (int i = 0; i < algo.vStsStripsB.size(); i++) // algo_tmp.vStsStripsB.push_back(L1Strip(algo.vStsStripsB[i], iEv)); // for (int i = 0; i < algo.vStsHits.size(); i++) // algo_tmp.vStsHits.push_back(L1StsHit(algo.vStsHits[i], iEv, stSize, stBSize)); // } // iEv // algo = algo_tmp; const bool flag = 0; int lStsHitsStartIndex[11], lStsHitsStopIndex[11]; std::vector< unsigned char > lvSFlag; std::vector< unsigned char > lvSFlagB; // if(flag){ // for (int ii=0; ii<11; ii++) { // lStsHitsStartIndex[ii] = algo.StsHitsStartIndex[ii]; // lStsHitsStopIndex[ii] = algo.StsHitsStopIndex[ii]; // }; // for (unsigned ii=0; ii> geo[i]; // cout << geo[i] << endl; }; size = i; fgeo.close(); cout << " -I- Geometry read successfully " << endl; } void L1AlgoInter::ReadStAPAlgoData() { static int iEvent = 1; static ifstream fadata; static char fname[100]; if (iEvent <= maxNEvent){ if ( iEvent == 1 ){ strcpy(fname, work_dir); strcat(fname, "data_algo.txt"); fadata.open(fname); }; cout << " -I- begin read " << iEvent << " event algo data from file " << fname << endl; algo.vStsHits.clear(); algo.vStsStrips.clear(); algo.vStsStripsB.clear(); algo.vSFlag.clear(); algo.vSFlagB.clear(); // check correct position in file char s[] = "EVENT: "; int nEv; fadata >> s; fadata >> nEv; if (nEv != iEvent) cout << " -E- Can't read event number " << iEvent << " from file " << fname << endl; // cout << s << "|" << nEv << endl; int kk; cin >> kk; int n; // number of elements // read algo.vStsStrips fadata >> n; for (int i = 0; i < n; i++){ fscal element; unsigned short int element2; fadata >> element >> element2; algo.vStsStrips.push_back(L1Strip(element,element2)); }; // read algo.vStsStripsB fadata >> n; for (int i = 0; i < n; i++){ fscal element; unsigned short int element2; fadata >> element >> element2; algo.vStsStripsB.push_back(L1Strip(element,element2)); }; // read algo.vSFlag fadata >> n; for (int i = 0; i < n; i++){ int element; fadata >> element; algo.vSFlag.push_back((unsigned char)element); }; // read algo.vSFlagB fadata >> n; for (int i = 0; i < n; i++){ int element; fadata >> element; algo.vSFlagB.push_back((unsigned char)element); }; // read algo.vStsHits fadata >> n; int element_f; // for convert int element_b; int element_n; for (int i = 0; i < n; i++){ L1StsHit element; fadata >> element_f >> element_b >> element_n; element.f = (unsigned short int) element_f; element.b = (unsigned short int) element_b; element.n = (unsigned short int) element_n; algo.vStsHits.push_back(element); }; // read StsHitsStartIndex and StsHitsStopIndex n = 20; for (int i = 0; i < n; i++){ fadata >> algo.StsHitsStartIndex[i]; }; for (int i = 0; i < n; i++){ fadata >> algo.StsHitsStopIndex[i]; }; cout << iEvent << " event data read from file " << fname << " successfully" << endl; // if (iEvent == maxNEvent) fadata.close(); } iEvent++; }; /// Write reconstracted tracks and hits in file /// Format of write: /// /// Event: [x] /// [nTrack] /// Tr[iTrack] [NHits] /// [Momentum] /// [tf1] ... [tf6] [cf1] ... [cf15] /// [tl1] ... [tl6] [cl1] ... [cl15] /// [chi2] [NDF] /// [h1] [h2] [h3] ... /// Tr[iTrack] [NHits] /// ...................... /// /// x - number of current event /// nTrack - number of all current track /// iTrack - number of current track /// NHits - number of hits in current track /// tf1-tf6 - TFirst, cf1-cf15 - CFirst /// tl1-tl6 - TLast, cl1-cl15 - CLast /// h1,h2,h3,... - hits void L1AlgoInter::WriteResults(){ static int iEvent = 1; static ofstream faout; static char fname[100]; if ( iEvent == 1 ){ strcpy(fname, work_dir); strcat(fname, "results_algo.txt"); faout.open(fname); // if first event recreate a output file } else{ faout.open(fname, fstream::app); }; cout << " -I- write " << iEvent << " event algo results data to file " << fname << endl; faout << "Event: " << nEvent << endl; // // write vRecoHits // int n = vRecoHits.size(); // number of elements // faout << " vRecoHits" << endl; // faout << n << endl; // for (int i = 0; i < n; i++){ // faout << vRecoHits[i] << endl; // }; // write vTracks int n = algo.vTracks.size(); // number of elements int start_hit = 0; // for read hits from vRecoHits[] faout << n << endl; for (int i = 0; i < n; i++){ faout << "Tr" << i+1 << " "; faout << (int)algo.vTracks[i].NHits << endl; // transform from unsigned char to int for normal reading\writing faout << algo.vTracks[i].Momentum << endl; for (int k = 0; k < 6; k++){ faout << algo.vTracks[i].TFirst[k] << " "; }; faout << endl; for (int k = 0; k < 15; k++){ faout << algo.vTracks[i].CFirst[k] << " "; }; faout << endl; for (int k = 0; k < 6; k++){ faout << algo.vTracks[i].TLast[k] << " "; }; faout << endl; for (int k = 0; k < 15; k++){ faout << algo.vTracks[i].CLast[k] << " "; }; faout << endl; faout << algo.vTracks[i].chi2 << " " << algo.vTracks[i].NDF << endl; for( int k = 0; k < algo.vTracks[i].NHits; k++ ){ // find corespondent to current track hits and write faout << algo.vRecoHits[start_hit++] << " "; } faout << endl; }; faout.close(); if ( iEvent == maxNEvent ){ cout << " -I- vRecoHits and vTracks was written in " << fname << endl; }; iEvent++; };