00001
00012
00013 #include "Trigger/MdcTSF.h"
00014
00015 #include "Identifier/Identifier.h"
00016 #include "Identifier/MdcID.h"
00017
00018 #include "RawEvent/RawDataUtil.h"
00019 #include "RawEvent/DigiEvent.h"
00020
00021 #include <TString.h>
00022 #include <fstream>
00023 #include <vector>
00024
00025 using namespace std;
00026
00027 MdcTSF* MdcTSF::mdc_Pointer=0;
00028 MdcTSF* MdcTSF::get_Mdc(void) {
00029 if(!mdc_Pointer) mdc_Pointer = new MdcTSF();
00030 return mdc_Pointer;
00031 }
00032
00033 MdcTSF::MdcTSF()
00034 {
00035 ReadLut();
00036
00037 }
00038 MdcTSF::~MdcTSF()
00039 {
00040 }
00041 void MdcTSF::setMdcDigi(std::vector<int>& vmdcHit)
00042 {
00043 std::vector<int> vtmp;
00044 vtmp.clear();
00045 digiId.clear();
00046
00047 for(std::vector<int>::iterator iter = vmdcHit.begin(); iter != vmdcHit.end(); iter += 2)
00048 {
00049 int layer = *iter;
00050 int wire = *(iter + 1);
00051 if(layer<=19) { vtmp.push_back(layer); vtmp.push_back(wire); }
00052 if(layer>=36&&layer<=39)
00053 {
00054 wire = int(wire/2);
00055 vtmp.push_back(layer);
00056 vtmp.push_back(wire);
00057 }
00058 }
00059
00060
00061 for(std::vector<int>::iterator iter = vtmp.begin(); iter != vtmp.end(); iter += 2) {
00062 bool ifsamelem = false;
00063 int layerId = *(iter);
00064 int cellId = *(iter+1);
00065 for(std::vector<int>::iterator iter_tmp = iter; iter_tmp != vtmp.end(); iter_tmp += 2) {
00066 if((iter_tmp+2) != vtmp.end()) {
00067 int layerId_tmp = *(iter_tmp+2);
00068 int cellId_tmp = *(iter_tmp+3);
00069 if((layerId == layerId_tmp) && (cellId == cellId_tmp)) ifsamelem = true;
00070 }
00071 }
00072 if(ifsamelem == false) {
00073 digiId.push_back(layerId);
00074 digiId.push_back(cellId);
00075
00076 }
00077 }
00078
00079 }
00080 void MdcTSF::CountTS()
00081 {
00082
00083
00084 for(int i=0;i<48;i++)
00085 {
00086 SL1PivotCellHit[i] = 0;
00087 SL1TSF[i] = 0;
00088 for(int j=0;j<8;j++)
00089 {
00090 SL1HitCount[i][j] = 0;
00091 }
00092 }
00093
00094 for(int i=0;i<80;i++)
00095 {
00096 SL2PivotCellHit[i] = 0;
00097 SL2TSF[i] = 0;
00098 for(int j=0;j<12;j++)
00099 {
00100 SL2HitCount[i][j] = 0;
00101 }
00102 }
00103
00104 for(int i=0;i<88;i++)
00105 {
00106 SL3PivotCellHit[i] = 0;
00107 SL3TSF[i] = 0;
00108 for(int j=0;j<16;j++)
00109 {
00110 SL3HitCount[i][j] = 0;
00111 }
00112 }
00113
00114 for(int i=0;i<112;i++)
00115 {
00116 SL4PivotCellHit[i] = 0;
00117 SL4TSF[i] = 0;
00118 for(int j=0;j<22;j++)
00119 {
00120 SL4HitCount[i][j] = 0;
00121 }
00122 }
00123
00124 for(int i=0;i<128;i++)
00125 {
00126 SL5PivotCellHit[i] = 0;
00127 SL5TSF[i] = 0;
00128 for(int j=0;j<31;j++)
00129 {
00130 SL5HitCount[i][j] = 0;
00131 }
00132 }
00133
00134 for(int i=0;i<128;i++)
00135 {
00136 SL10PivotCellHit[i] = 0;
00137 SL10TSF[i] = 0;
00138 for(int j=0;j<81;j++)
00139 {
00140 SL10HitCount[i][j] = 0;
00141 }
00142 }
00143
00144
00145
00146 int layer,cell,superlayer,ln;
00147
00148 for(std::vector<int>::iterator iter=digiId.begin();iter!=digiId.end();iter+=2)
00149 {
00150 layer = *iter;
00151 cell = *(iter+1);
00152 if(layer<=19)
00153 {
00154 superlayer = (int) layer/4+1;
00155 ln = layer%4;
00156 if(superlayer == 1)
00157 {
00158 if(ln==2) SL1PivotCellHit[cell] = 1;
00159 for(unsigned int i = 0;i < SL1.size(); i++)
00160 {
00161 for(unsigned int j = 0; j < SL1[i].size()/4; j++) {
00162 if(SL1[i][3-ln+j*4] == cell+1) SL1HitCount[i][j] += 1;
00163 }
00164 }
00165 }
00166
00167 if(superlayer == 2)
00168 {
00169 if(ln==2) SL2PivotCellHit[cell] = 1;
00170 for(unsigned int i = 0;i < SL2.size(); i++)
00171 {
00172 for(unsigned int j = 0; j < SL2[i].size()/4; j++) {
00173 if(SL2[i][3-ln+j*4] == cell+1) SL2HitCount[i][j] += 1;
00174 }
00175 }
00176 }
00177
00178 if(superlayer==3)
00179 {
00180 if(ln==2) SL3PivotCellHit[cell] = 1;
00181 for(unsigned int i = 0;i < SL3.size(); i++)
00182 {
00183 for(unsigned int j = 0; j < SL3[i].size()/4; j++) {
00184 if(SL3[i][3-ln+j*4] == cell+1) SL3HitCount[i][j] += 1;
00185 }
00186 }
00187 }
00188
00189 if(superlayer==4)
00190 {
00191 if(ln==2) SL4PivotCellHit[cell] = 1;
00192 for(unsigned int i = 0;i < SL4.size(); i++)
00193 {
00194 for(unsigned int j = 0; j < SL4[i].size()/4; j++) {
00195 if(SL4[i][3-ln+j*4] == cell+1) SL4HitCount[i][j] += 1;
00196 }
00197 }
00198 }
00199
00200 if(superlayer==5)
00201 {
00202 if(ln==1) SL5PivotCellHit[cell] = 1;
00203 for(unsigned int i = 0;i < SL5.size(); i++)
00204 {
00205 for(unsigned int j = 0; j < SL5[i].size()/4; j++) {
00206 if(SL5[i][3-ln+j*4] == cell+1) SL5HitCount[i][j] += 1;
00207 }
00208 }
00209 }
00210 }
00211 else
00212 {
00213 superlayer = (int) layer/4+1;
00214 ln = layer%4;
00215 if(ln==1) SL10PivotCellHit[cell] = 1;
00216 for(unsigned int i = 0;i < SL10.size(); i++)
00217 {
00218 for(unsigned int j = 0; j < SL10[i].size()/4; j++) {
00219 if(SL10[i][3-ln+j*4] == cell+1) SL10HitCount[i][j] += 1;
00220 }
00221 }
00222 }
00223 }
00224 }
00225 void MdcTSF::GetTS()
00226 {
00227 CountTS();
00228
00229 for(int i=0; i<48; i++)
00230 for(int j=0; j<8; j++)
00231 {
00232 if(SL1HitCount[i][j] >= 3) { SL1TSF[i] = 1; break; }
00233 }
00234
00235 for(int i=0; i<80; i++)
00236 for(int j=0; j<12; j++)
00237 {
00238 if(SL2HitCount[i][j] >= 3) { SL2TSF[i] = 1; break; }
00239 }
00240
00241 for(int i = 0; i < 88; i++)
00242 for(int j = 0; j < 16; j++)
00243 {
00244 if(SL3HitCount[i][j] >= 3) { SL3TSF[i] = 1; break; }
00245 }
00246
00247 for(int i = 0; i < 112; i++)
00248 for(int j = 0; j < 22; j++)
00249 {
00250 if(SL4HitCount[i][j] >= 3) { SL4TSF[i] = 1; break; }
00251 }
00252
00253 for(int i = 0; i < 128; i++)
00254 for(int j = 0; j < 31; j++)
00255 {
00256 if(SL5HitCount[i][j] >= 3) { SL5TSF[i] = 1; break; }
00257 }
00258
00259 for(int i = 0; i < 128; i++)
00260 for(int j = 0; j < 81; j++)
00261 {
00262 if(SL10HitCount[i][j] >= 3) { SL10TSF[i] = 1; break; }
00263 }
00264
00265
00266
00267
00268
00269 }
00270
00271 void MdcTSF::ReadLut()
00272 {
00273 fstream readin;
00274 int ncell=0,pl=0;
00275 int a,b,l4,l3,l2,l1;
00276 SL1.clear();
00277 SL2.clear();
00278 SL3.clear();
00279 SL4.clear();
00280 SL5.clear();
00281 SL10.clear();
00282 for(int n=1;n<6;n++)
00283 {
00284 if(n==1) { ncell=48; pl=3; }
00285 if(n==2) { ncell=80; pl=7; }
00286 if(n==3) { ncell=88; pl=11; }
00287 if(n==4) { ncell=112; pl=15; }
00288 if(n==5) { ncell=128; pl=18; }
00289
00290 for(int i=1;i<(ncell+1);i++)
00291 {
00292 std::vector<int> tmp;
00293 tmp.clear();
00294 int num=0;
00295 TString filename = TString(getenv( "TRIGGERROOT" ));
00296 filename+="/data/tsf";
00297 filename+=n;
00298 filename+="/TSF-SL";
00299 filename+=n;
00300 filename+="-L";
00301 filename+=pl;
00302 filename+="-C";
00303 filename+=i;
00304 filename+=".pat";
00305 readin.clear();
00306 readin.open(filename,ios_base::in);
00307 if(!readin) cerr<<"can not open the file "<<filename<<endl;
00308 while(readin.good())
00309 {
00310 readin>>a>>b>>l4>>l3>>l2>>l1;
00311 num++;
00312 }
00313 readin.close();
00314 readin.clear();
00315 readin.open(filename,ios_base::in);
00316 if(!readin) cerr<<"can not open the file again "<<filename<<endl;
00317 for(int j=0;j<(num-1);j++)
00318 {
00319 readin>>a>>b>>l4>>l3>>l2>>l1;
00320 tmp.push_back(l4);
00321 tmp.push_back(l3);
00322 tmp.push_back(l2);
00323 tmp.push_back(l1);
00324 }
00325 readin.close();
00326 if(n==1) SL1.push_back(tmp);
00327 if(n==2) SL2.push_back(tmp);
00328 if(n==3) SL3.push_back(tmp);
00329 if(n==4) SL4.push_back(tmp);
00330 if(n==5) SL5.push_back(tmp);
00331 }
00332 }
00333 for(int i=1;i<129;i++)
00334 {
00335 std::vector<int> tmp1;
00336 tmp1.clear();
00337 int num=0;
00338
00339 TString filename = TString(getenv( "TRIGGERROOT" ));
00340 filename+="/data/tsf10C/TSF-SL10C-L38-C";
00341 filename+=i;
00342 filename+=".pat";
00343 readin.clear();
00344 readin.open(filename,ios_base::in);
00345 if(!readin) cerr<<"can not open the file "<<filename<<endl;
00346 while(readin.good())
00347 {
00348 readin>>a>>b>>l4>>l3>>l2>>l1;
00349 num++;
00350 }
00351 readin.close();
00352 readin.clear();
00353 readin.open(filename,ios_base::in);
00354 if(!readin) cerr<<"can not open the file again "<<filename<<endl;
00355
00356 for(int j=0;j<(num-1);j++)
00357 {
00358 readin>>a>>b>>l4>>l3>>l2>>l1;
00359 tmp1.push_back(l4);
00360 tmp1.push_back(l3);
00361 tmp1.push_back(l2);
00362 tmp1.push_back(l1);
00363 }
00364 readin.close();
00365 SL10.push_back(tmp1);
00366 }
00367 }
00368 void MdcTSF::Dump()
00369 {
00370 std::vector<int> combine_size;
00371 cout<<endl;
00372 cout<<" ***************check data file tsf: ***************** "<<endl;
00373 cout<<"*--------------------------BEGIN-------------------------------*"<<endl;
00374 cout<<endl;
00375
00376 cout<<" -------------------SL1---------------------- "<<endl;
00377 combine_size.clear();
00378 for(unsigned int i=0; i<SL1.size(); i++) {
00379 cout<<"Cell ID --> "<<i<<endl;
00380 combine_size.push_back(SL1[i].size());
00381 for(unsigned int j=0; j<SL1[i].size(); j++) {
00382 cout<<SL1[i][j]<<" ";
00383 if((j+1)%4==0) cout<<endl;
00384 }
00385 cout<<endl;
00386 }
00387 sort(combine_size.begin(),combine_size.end());
00388 cout<<"The Max Number of Combination is "<<combine_size[combine_size.size()-1]/4<<endl;
00389 cout<<endl;
00390
00391 cout<<" -------------------SL2---------------------- "<<endl;
00392 combine_size.clear();
00393 for(unsigned int i=0; i<SL2.size(); i++) {
00394 cout<<"Cell ID --> "<<i<<endl;
00395 combine_size.push_back(SL2[i].size());
00396 for(unsigned int j=0; j<SL2[i].size(); j++) {
00397 cout<<SL2[i][j]<<" ";
00398 if((j+1)%4==0) cout<<endl;
00399 }
00400 cout<<endl;
00401 }
00402 sort(combine_size.begin(),combine_size.end());
00403 cout<<"The Max Number of Combination is "<<combine_size[combine_size.size()-1]/4<<endl;
00404 cout<<endl;
00405
00406 cout<<" -------------------SL3---------------------- "<<endl;
00407 combine_size.clear();
00408 for(unsigned int i=0; i<SL3.size(); i++) {
00409 cout<<"Cell ID --> "<<i<<endl;
00410 combine_size.push_back(SL3[i].size());
00411 for(unsigned int j=0; j<SL3[i].size(); j++) {
00412 cout<<SL3[i][j]<<" ";
00413 if((j+1)%4==0) cout<<endl;
00414 }
00415 cout<<endl;
00416 }
00417 sort(combine_size.begin(),combine_size.end());
00418 cout<<"The Max Number of Combination is "<<combine_size[combine_size.size()-1]/4<<endl;
00419 cout<<endl;
00420
00421 cout<<" -------------------SL4---------------------- "<<endl;
00422 combine_size.clear();
00423 for(unsigned int i=0; i<SL4.size(); i++) {
00424 cout<<"Cell ID --> "<<i<<endl;
00425 combine_size.push_back(SL4[i].size());
00426 for(unsigned int j=0; j<SL4[i].size(); j++) {
00427 cout<<SL4[i][j]<<" ";
00428 if((j+1)%4==0) cout<<endl;
00429 }
00430 cout<<endl;
00431 }
00432 sort(combine_size.begin(),combine_size.end());
00433 cout<<"The Max Number of Combination is "<<combine_size[combine_size.size()-1]/4<<endl;
00434 cout<<endl;
00435
00436 cout<<" -------------------SL5---------------------- "<<endl;
00437 combine_size.clear();
00438 for(unsigned int i=0; i<SL5.size(); i++) {
00439 cout<<"Cell ID --> "<<i<<endl;
00440 combine_size.push_back(SL5[i].size());
00441 for(unsigned int j=0; j<SL5[i].size(); j++) {
00442 cout<<SL5[i][j]<<" ";
00443 if((j+1)%4==0) cout<<endl;
00444 }
00445 cout<<endl;
00446 }
00447 sort(combine_size.begin(),combine_size.end());
00448 cout<<"The Max Number of Combination is "<<combine_size[combine_size.size()-1]/4<<endl;
00449 cout<<endl;
00450
00451 cout<<" -------------------SL10---------------------- "<<endl;
00452 combine_size.clear();
00453 for(unsigned int i=0; i<SL10.size(); i++) {
00454 cout<<"Cell ID --> "<<i<<endl;
00455 combine_size.push_back(SL10[i].size());
00456 for(unsigned int j=0; j<SL10[i].size(); j++) {
00457 cout<<SL10[i][j]<<" ";
00458 if((j+1)%4==0) cout<<endl;
00459 }
00460 cout<<endl;
00461 }
00462 sort(combine_size.begin(),combine_size.end());
00463 cout<<"The Max Number of Combination is "<<combine_size[combine_size.size()-1]/4<<endl;
00464 cout<<endl;
00465
00466 cout<<"*---------------------------END------------------------------*"<<endl;
00467 }