1#include "MdcHoughFinder/HoughHitList.h"
2#include "Identifier/Identifier.h"
3#include "Identifier/MdcID.h"
4#include "McTruth/MdcMcHit.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/Bootstrap.h"
7#include "GaudiKernel/IInterface.h"
8#include "GaudiKernel/Kernel.h"
9#include "GaudiKernel/Service.h"
10#include "GaudiKernel/SvcFactory.h"
11#include "GaudiKernel/IDataProviderSvc.h"
25 std::vector<HoughHit> emptyHitList;
26 emptyHitList.swap(_houghHitList);
50 _houghHitList.push_back(a);
55 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
56 for (;
iter != mdcDigiVec.end();
iter++) {
57 const MdcDigi*
const digi = (*iter);
62 _houghHitList.push_back(hit);
75 const int maxCell[43] = {
76 40,44,48,56, 64,72,80,80, 76,76,88,88,
77 100,100,112,112, 128,128,140,140, 160,160,160,160,
78 176,176,176,176, 208,208,208,208, 240,240,240,240,
79 256,256,256,256, 288,288,288 };
80 vector<HoughHit> vec_HoughHit[43];
81 vector<HoughHit>::const_iterator
iter=_houghHitList.begin();
82 for(
int order=0;
iter!=_houghHitList.end();
iter++,order++){
83 int layer = (*iter).getLayerId();
85 vec_HoughHit[layer].push_back(*
iter);
87 vector<HoughHit> vec_HoughHit_del;
89 for(
int i=0;i<43;i++){
92 vector<int> vec_seeds;
93 std::sort(vec_HoughHit[i].begin(),vec_HoughHit[i].end(),
small_layer);
94 if(vec_HoughHit[i].size()<=4)
continue;
98 for(
unsigned int j=0;j<vec_HoughHit[i].size()-4;j++){
99 vector<int>::iterator iter_hit = find(vec_seeds.begin(),vec_seeds.end(),vec_HoughHit[i][j].getWireId());
100 if( iter_hit!=vec_seeds.end() )
continue;
101 int wire_last=vec_HoughHit[i][j].getWireId();
107 for(
unsigned int k=vec_HoughHit[i].size()-j-1;k>0;k--){
108 wire=vec_HoughHit[i][j+k].getWireId();
109 int charge = vec_HoughHit[i][j+k].getCharge();
110 int driftTime = vec_HoughHit[i][j+k].driftTime();
114 if( (wire-maxCell[i]+1)!=wire_last || (
charge>0 && driftTime>0 && driftTime<800) )
break;
116 wire_last= wire-maxCell[i];
120 vec_seeds.push_back(wire+4-maxCell[i]);
121 vec_seeds.push_back(wire+3);
122 vec_seeds.push_back(wire+2);
123 vec_seeds.push_back(wire+1);
124 vec_seeds.push_back(wire);
126 if(seeds>5) vec_seeds.push_back(wire);
130 for(
unsigned int k=1;k<vec_HoughHit[i].size()-j;k++){
131 vector<int>::iterator iter_hit0 = find(vec_seeds.begin(),vec_seeds.end(),vec_HoughHit[i][j].getWireId());
132 if( iter_hit0!=vec_seeds.end() )
continue;
133 wire=vec_HoughHit[i][j+k].getWireId();
134 int charge = vec_HoughHit[i][j+k].getCharge();
135 int driftTime = vec_HoughHit[i][j+k].driftTime();
138 if( wire<=maxCell[i] ) {
140 if( (wire-1)!=wire_last || (
charge>0 && driftTime>0 && driftTime<800))
break;
146 vec_seeds.push_back(wire-4);
147 vec_seeds.push_back(wire-3);
148 vec_seeds.push_back(wire-2);
149 vec_seeds.push_back(wire-1);
150 vec_seeds.push_back(wire);
152 if(seeds>5) vec_seeds.push_back(wire);
158 for(
unsigned int k=1;k<vec_HoughHit[i].size()-j;k++){
159 wire=vec_HoughHit[i][j+k].getWireId();
160 int charge = vec_HoughHit[i][j+k].getCharge();
161 int driftTime = vec_HoughHit[i][j+k].driftTime();
164 if( wire<=maxCell[i] ) {
166 if( (wire-1)!=wire_last || (
charge>0 && driftTime>0 && driftTime<800))
break;
172 vec_seeds.push_back(wire-4);
173 vec_seeds.push_back(wire-3);
174 vec_seeds.push_back(wire-2);
175 vec_seeds.push_back(wire-1);
176 vec_seeds.push_back(wire);
178 if(seeds>5) vec_seeds.push_back(wire);
184 for(
unsigned int ihit=0;ihit<vec_seeds.size();ihit++){
186 for(
unsigned int jhit=0;jhit<vec_HoughHit[i].size();jhit++){
187 if(vec_HoughHit[i][jhit].getWireId()==vec_seeds[ihit]) vec_HoughHit_del.push_back(vec_HoughHit[i][jhit]);
191 for(
unsigned int ihit=0;ihit<vec_HoughHit_del.size();ihit++){
193 remove(vec_HoughHit_del[ihit]);
198 vector<HoughHit>::iterator
iter = _houghHitList.begin();
199 for(;
iter!=_houghHitList.end();
iter++){
200 if( hit.
digi() == (*iter).digi() ) {
209 const MdcMcHit* truthHitPtr[43][288];
210 for(
int i=0;i<43;i++){
for(
int j=0;j<288;j++){ truthHitPtr[i][j]=NULL; } }
211 IDataProviderSvc* eventSvc = NULL;
212 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
213 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc,
"/Event/MC/MdcMcHitCol");
215 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
216 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++) {
217 const Identifier id= (*iter_mchit)->identify();
220 const MdcMcHit* mcHit = (*iter_mchit);
221 truthHitPtr[l][
w] = mcHit;
224 std::cout<<__FILE__<<
" Could not get MdcMcHitCol "<<std::endl;
230 int nHitTruthAdd = 0;
231 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
232 int l = (*iter).getLayerId();
233 int w = (*iter).getWireId();
234 int mcTkId = (*iter).digi()->getTrackIndex();
235 if( mcTkId>=1000 ) mcTkId-=1000;
236 if(mcTkId>=0 && NULL!=truthHitPtr[l][
w]) {
237 (*iter).setTruthInfo(truthHitPtr[l][
w]);
239 if(mcTkPars.find(mcTkId)!= mcTkPars.end()){
283 if( mcTkId<0 ) (*iter).setStyle(-999);
293 if( _houghHitList.size()!=0) _houghHitList[0].setCirList(0);
294 for(
unsigned int id = 1;
id <_houghHitList.size();
id++){
296 if( ((_houghHitList[
id].getLayerId() < _houghHitList[
id-1].getLayerId()) )&& (cirlist==0||cirlist==2) ) cirlist++;
297 if(_houghHitList[
id].getLayerId() > _houghHitList[
id-1].getLayerId() && (cirlist==1||cirlist==3) ) cirlist++;
298 if(cirlist>3) cirlist=999;
299 _houghHitList[id].setCirList(cirlist);
301 int label_out_circle=999;
305 for(
unsigned int id = 0;
id <_houghHitList.size();
id++){
306 if(_houghHitList[
id].getStyle()==-999)
continue;
307 if( _houghHitList[
id].getLayerId()>max_layer) max_layer=_houghHitList[id].getLayerId();
309 for(
unsigned int id = 1;
id <_houghHitList.size();
id++){
310 if( (_houghHitList[
id-1].getLayerId() == _houghHitList[
id].getLayerId()) && (_houghHitList[
id].getLayerId() == _houghHitList[
id+1].getLayerId()) && (_houghHitList[
id+1].getLayerId() == _houghHitList[
id+2].getLayerId()) && (_houghHitList[
id+2].getLayerId() == _houghHitList[
id+3].getLayerId()) && _houghHitList[
id].getLayerId() == max_layer) label_out_circle=_houghHitList[
id-1].getLayerId();
312 for(
int unsigned id = 0;
id <_houghHitList.size();
id++){
313 if ( _houghHitList[
id].getLayerId() == label_out_circle ) label_num++;
314 if( label_num==1 ) label_fist = id;
316 for(
int id = 0;
id <label_num/2;
id++){
317 if( label_num %2 == 0 ) _houghHitList[label_fist+label_num/2+id].setCirList(1);
318 if( label_num %2 == 1 ) _houghHitList[label_fist+label_num/2+
id+1].setCirList(1);
326 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
329 std::cout<<std::endl;
333 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
334 (*iter).printTruth();
336 std::cout<<std::endl;
340 std::cout<<
"MdcHoughFinder hit list: nHit="<<_houghHitList.size()<<std::endl;
345 return _houghHitList;
348 return _houghHitList;
351 int size=_houghHitList.size();
352 int n0,
n1,
n2,n3,n4,n5,n6;
353 n0=
n1=
n2=n3=n4=n5=n6=0;
354 for(
int i=0;i<size;i++){
355 int cir= _houghHitList[i].getCirList();
356 int index = _houghHitList[i].digi()->getTrackIndex();
357 int style= _houghHitList[i].getStyle();
359 if( style == 1 )
n1++;
360 if( style == 2 )
n2++;
361 if( index < 0 ) n3++;
362 if( index >=0 && cir<=1 && style==0) n4++;
363 if( index <0 || cir>1 ) n5++;
364 if( index >=0 && cir==0 && style==0) n6++;
366 if( select == 0 )
return n0;
367 else if( select == 1 )
return n1;
368 else if( select == 2 )
return n2;
369 else if( select == 3 )
return n3;
370 else if( select == 4 )
return n4;
371 else if( select == 5 )
return n5;
372 else if( select == 6 )
return n6;
376 int size=_houghHitList.size();
377 int n0,
n1,
n2,n3,n4,n5,n6;
378 n0=
n1=
n2=n3=n4=n5=n6=0;
379 for(
int i=0;i<size;i++){
380 int cir= _houghHitList[i].getCirList();
381 int index = _houghHitList[i].digi()->getTrackIndex();
382 int type = _houghHitList[i].getSlayerType();
383 int style= _houghHitList[i].getStyle();
385 if(
type==0 && style == 1 )
n1++;
386 if(
type==0 && style == 2 )
n2++;
387 if(
type==0 && index < 0 ) n3++;
388 if(
type==0 && index >=0 && cir<=1 && style ==0) n4++;
389 if(
type==0 && (index <0 || cir>1) ) n5++;
390 if(
type==0 && index >=0 && cir==0 && style ==0) n6++;
392 if ( select == 0 )
return n0;
393 else if ( select == 1 )
return n1;
394 else if ( select == 2 )
return n2;
395 else if ( select == 3 )
return n3;
396 else if ( select == 4 )
return n4;
397 else if ( select == 5 )
return n5;
398 else if ( select == 6 )
return n6;
402 int size=_houghHitList.size();
403 int n0,
n1,
n2,n3,n4,n5,n6;
404 n0=
n1=
n2=n3=n4=n5=n6=0;
405 for(
int i=0;i<size;i++){
406 int cir= _houghHitList[i].getCirList();
407 int index = _houghHitList[i].digi()->getTrackIndex();
408 int type = _houghHitList[i].getSlayerType();
409 int style= _houghHitList[i].getStyle();
411 if(
type!=0 && style == 1 )
n1++;
412 if(
type!=0 && style == 2 )
n2++;
413 if(
type!=0 && index < 0 ) n3++;
414 if(
type!=0 && index >=0 && cir<=1 && style==0) n4++;
415 if(
type!=0 && (index <0 || cir>1) ) n5++;
416 if(
type!=0 && index >=0 && cir==0 && style==0) n6++;
418 if( select == 0 )
return n0;
419 else if( select == 1 )
return n1;
420 else if( select == 2 )
return n2;
421 else if( select == 3 )
return n3;
422 else if( select == 4 )
return n4;
423 else if( select == 5 )
return n5;
424 else if( select == 6 )
return n6;
bool small_layer(const HoughHit &a, const HoughHit &b)
std::vector< MdcDigi * > MdcDigiVec
int addMdcDigiList(MdcDigiVec mdcDigiVec)
void remove(const HoughHit &hit)
int getHitNumA(int) const
HoughHitType type() const
int addTruthInfo(std::map< int, const HepVector > mcTkPars)
const std::vector< HoughHit > & getList() const
int getHitNumS(int) const
const MdcDigi * digi() const
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)