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"
12#include "McTruth/CgemMcHit.h"
14#include "Identifier/CgemID.h"
32 std::vector<HoughHit> emptyHitList;
33 emptyHitList.swap(_houghHitList);
57 _houghHitList.push_back(a);
62 int nHit = _houghHitList.size();
63 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
64 for (;
iter != mdcDigiVec.end();
iter++) {
65 const MdcDigi*
const digi = (*iter);
71 _houghHitList.push_back(hit);
80 int nHit = _houghHitList.size();
81 RecCgemClusterCol::iterator
iter = cgemClusterVec->begin();
82 for (;
iter != cgemClusterVec->end();
iter++) {
86 _houghHitList.push_back(hit);
97 int nHit = _houghHitList.size();
99 IDataProviderSvc* eventSvc = NULL;
100 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
101 SmartDataPtr<RecCgemClusterCol> cgemClusterVec(eventSvc,
"/Event/Recon/RecCgemClusterCol");
102 RecCgemClusterCol::iterator
iter = cgemClusterVec->begin();
103 for (;
iter != cgemClusterVec->end();
iter++) {
107 _houghHitList.push_back(hit);
121 const int maxCell[43] = {
122 40,44,48,56, 64,72,80,80,
123 76,76,88,88, 100,100,112,112, 128,128,140,140,
124 160,160,160,160, 176,176,176,176, 208,208,208,208, 240,240,240,240,
125 256,256,256,256, 288,288,288 };
126 vector<HoughHit> vec_HoughHit[43];
127 vector<HoughHit>::const_iterator
iter=_houghHitList.begin();
128 for(
int order=0;
iter!=_houghHitList.end();
iter++,order++){
129 int layer = (*iter).getLayerId();
131 vec_HoughHit[layer].push_back(*
iter);
133 vector<HoughHit> vec_HoughHit_del;
135 for(
int i=0;i<43;i++){
138 vector<int> vec_seeds;
139 std::sort(vec_HoughHit[i].begin(),vec_HoughHit[i].end(),
small_layer);
140 if(vec_HoughHit[i].size()<=4)
continue;
144 for(
unsigned int j=0;j<vec_HoughHit[i].size()-4;j++){
145 vector<int>::iterator iter_hit = find(vec_seeds.begin(),vec_seeds.end(),vec_HoughHit[i][j].getWireId());
146 if( iter_hit!=vec_seeds.end() )
continue;
147 int wire_last=vec_HoughHit[i][j].getWireId();
153 for(
unsigned int k=vec_HoughHit[i].size()-j-1;k>0;k--){
154 wire=vec_HoughHit[i][j+k].getWireId();
155 int charge = vec_HoughHit[i][j+k].getCharge();
156 int driftTime = vec_HoughHit[i][j+k].driftTime();
160 if( (wire-maxCell[i]+1)!=wire_last || (charge>0 && driftTime>0 && driftTime<800) )
break;
162 wire_last= wire-maxCell[i];
166 vec_seeds.push_back(wire+4-maxCell[i]);
167 vec_seeds.push_back(wire+3);
168 vec_seeds.push_back(wire+2);
169 vec_seeds.push_back(wire+1);
170 vec_seeds.push_back(wire);
172 if(seeds>5) vec_seeds.push_back(wire);
176 for(
unsigned int k=1;k<vec_HoughHit[i].size()-j;k++){
177 vector<int>::iterator iter_hit0 = find(vec_seeds.begin(),vec_seeds.end(),vec_HoughHit[i][j].getWireId());
178 if( iter_hit0!=vec_seeds.end() )
continue;
179 wire=vec_HoughHit[i][j+k].getWireId();
180 int charge = vec_HoughHit[i][j+k].getCharge();
181 int driftTime = vec_HoughHit[i][j+k].driftTime();
184 if( wire<=maxCell[i] ) {
186 if( (wire-1)!=wire_last || (charge>0 && driftTime>0 && driftTime<800))
break;
192 vec_seeds.push_back(wire-4);
193 vec_seeds.push_back(wire-3);
194 vec_seeds.push_back(wire-2);
195 vec_seeds.push_back(wire-1);
196 vec_seeds.push_back(wire);
198 if(seeds>5) vec_seeds.push_back(wire);
204 for(
unsigned int k=1;k<vec_HoughHit[i].size()-j;k++){
205 wire=vec_HoughHit[i][j+k].getWireId();
206 int charge = vec_HoughHit[i][j+k].getCharge();
207 int driftTime = vec_HoughHit[i][j+k].driftTime();
210 if( wire<=maxCell[i] ) {
212 if( (wire-1)!=wire_last || (charge>0 && driftTime>0 && driftTime<800))
break;
218 vec_seeds.push_back(wire-4);
219 vec_seeds.push_back(wire-3);
220 vec_seeds.push_back(wire-2);
221 vec_seeds.push_back(wire-1);
222 vec_seeds.push_back(wire);
224 if(seeds>5) vec_seeds.push_back(wire);
230 for(
unsigned int ihit=0;ihit<vec_seeds.size();ihit++){
232 for(
unsigned int jhit=0;jhit<vec_HoughHit[i].size();jhit++){
233 if(vec_HoughHit[i][jhit].getWireId()==vec_seeds[ihit]) vec_HoughHit_del.push_back(vec_HoughHit[i][jhit]);
237 for(
unsigned int ihit=0;ihit<vec_HoughHit_del.size();ihit++){
239 remove(vec_HoughHit_del[ihit]);
244 vector<HoughHit>::iterator
iter = _houghHitList.begin();
245 for(;
iter!=_houghHitList.end();
iter++){
247 if(hit.
getHitId()==(*iter).getHitId()){
256 const MdcMcHit* truthHitPtr[43][288];
257 for(
int i=0;i<43;i++){
for(
int j=0;j<288;j++){ truthHitPtr[i][j]=NULL; } }
258 IDataProviderSvc* eventSvc = NULL;
259 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
260 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc,
"/Event/MC/MdcMcHitCol");
262 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
263 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++) {
264 const Identifier id= (*iter_mchit)->identify();
267 const MdcMcHit* mcHit = (*iter_mchit);
268 truthHitPtr[l][w] = mcHit;
272 std::cout<<__FILE__<<
" Could not get MdcMcHitCol "<<std::endl;
279 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
280 SmartDataPtr<Event::CgemMcHitCol> cgemMcHitCol(eventSvc,
"/Event/MC/CgemMcHitCol");
282 std::cout<<__FILE__<<
" Could not get CgemMcHitCol "<<std::endl;
287 int nHitTruthAdd = 0;
288 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
289 if((*iter).getDetectorType()==
MDC){
290 int l = (*iter).getLayerId();
291 int w = (*iter).getWireId();
292 int mcTkId = (*iter).digi()->getTrackIndex();
293 if( mcTkId>=1000 ) mcTkId-=1000;
294 if(mcTkId>=0 && NULL!=truthHitPtr[l][w]) {
295 (*iter).setTruthInfo(truthHitPtr[l][w]);
297 if(mcTkPars.find(mcTkId)!= mcTkPars.end()){
341 if( mcTkId<0 ) (*iter).setStyle(-999);
347 }
else if((*iter).getDetectorType()==
CGEM){
348 double dphi_min(
M_PI);
350 Event::CgemMcHitCol::iterator iter_truth = cgemMcHitCol->begin();
352 bool findbegin(
false),findend(
false);
353 for(; iter_truth != cgemMcHitCol->end(); ++iter_truth){
354 double midx=((*iter_truth)->GetPositionXOfPrePoint()+(*iter_truth)->GetPositionXOfPostPoint())/2;
355 double midy=((*iter_truth)->GetPositionYOfPrePoint()+(*iter_truth)->GetPositionYOfPostPoint())/2;
356 double midz=((*iter_truth)->GetPositionZOfPrePoint()+(*iter_truth)->GetPositionZOfPostPoint())/2;
362 if((*iter_truth)->GetLayerID()!=(*iter).getLayerId())
continue;
363 double phi_true=atan2(midy,midx);
364 while(phi_true>2*
M_PI)phi_true-=2*
M_PI;
365 while(phi_true<0)phi_true+=2*
M_PI;
366 double dphi=(*iter).getCluster()->getrecphi()-phi_true;
367 if(fabs(dphi)<dphi_min){
369 cgemMcHit=(*iter_truth);
400 (*iter).setTruthInfo(cgemMcHit);
401 if(mcTkPars.find(cgemMcHit->GetTrackID())!= mcTkPars.end()){
413 if( _houghHitList.size()!=0) _houghHitList[0].setCirList(0);
414 for(
unsigned int id = 1;
id <_houghHitList.size();
id++){
416 if( ((_houghHitList[
id].getLayerId() < _houghHitList[
id-1].getLayerId()) )&& (cirlist==0||cirlist==2) ) cirlist++;
417 if(_houghHitList[
id].getLayerId() > _houghHitList[
id-1].getLayerId() && (cirlist==1||cirlist==3) ) cirlist++;
418 if(cirlist>3) cirlist=999;
419 _houghHitList[id].setCirList(cirlist);
421 int label_out_circle=999;
425 for(
unsigned int id = 0;
id <_houghHitList.size();
id++){
426 if(_houghHitList[
id].getStyle()==-999)
continue;
427 if( _houghHitList[
id].getLayerId()>max_layer) max_layer=_houghHitList[id].getLayerId();
429 for(
unsigned int id = 1;
id <_houghHitList.size();
id++){
430 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();
432 for(
int unsigned id = 0;
id <_houghHitList.size();
id++){
433 if ( _houghHitList[
id].getLayerId() == label_out_circle ) label_num++;
434 if( label_num==1 ) label_fist = id;
436 for(
int id = 0;
id <label_num/2;
id++){
437 if( label_num %2 == 0 ) _houghHitList[label_fist+label_num/2+id].setCirList(1);
438 if( label_num %2 == 1 ) _houghHitList[label_fist+label_num/2+
id+1].setCirList(1);
446 std::cout<<
"MdcHoughFinder hit list: nHit="<<_houghHitList.size()<<std::endl;
447 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
450 std::cout<<std::endl;
454 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
455 (*iter).printTruth();
457 std::cout<<std::endl;
461 std::cout<<
"MdcHoughFinder hit list: nHit="<<_houghHitList.size()<<std::endl;
462 for(std::vector<HoughHit>::iterator
iter = _houghHitList.begin();
iter!= _houghHitList.end();
iter++){
465 std::cout<<std::endl;
470 return _houghHitList;
473 return _houghHitList;
476 int size=_houghHitList.size();
477 int n0,
n1,
n2,n3,n4,n5,n6;
478 n0=
n1=
n2=n3=n4=n5=n6=0;
479 for(
int i=0;i<size;i++){
480 int cir= _houghHitList[i].getCirList();
481 int style= _houghHitList[i].getStyle();
483 if( style == 1 )
n1++;
484 if( style == 2 )
n2++;
485 if(_houghHitList[i].getDetectorType()==
MDC){
486 int index = _houghHitList[i].digi()->getTrackIndex();
487 if( index < 0 ) n3++;
488 if( index >=0 && cir<=1 && style==0) n4++;
489 if( index <0 || cir>1 ) n5++;
490 if( index >=0 && cir==0 && style==0) n6++;
493 if( select == 0 )
return n0;
494 else if( select == 1 )
return n1;
495 else if( select == 2 )
return n2;
496 else if( select == 3 )
return n3;
497 else if( select == 4 )
return n4;
498 else if( select == 5 )
return n5;
499 else if( select == 6 )
return n6;
503 int size=_houghHitList.size();
504 int n0,
n1,
n2,n3,n4,n5,n6;
505 n0=
n1=
n2=n3=n4=n5=n6=0;
506 for(
int i=0;i<size;i++){
507 int cir= _houghHitList[i].getCirList();
508 int type = _houghHitList[i].getSlayerType();
509 int style= _houghHitList[i].getStyle();
511 if(
type==0 && style == 1 )
n1++;
512 if(
type==0 && style == 2 )
n2++;
513 if(_houghHitList[i].getDetectorType()==
MDC){
514 int index = _houghHitList[i].digi()->getTrackIndex();
515 if(
type==0 && index < 0 ) n3++;
516 if(
type==0 && index >=0 && cir<=1 && style ==0) n4++;
517 if(
type==0 && (index <0 || cir>1) ) n5++;
518 if(
type==0 && index >=0 && cir==0 && style ==0) n6++;
521 if ( select == 0 )
return n0;
522 else if ( select == 1 )
return n1;
523 else if ( select == 2 )
return n2;
524 else if ( select == 3 )
return n3;
525 else if ( select == 4 )
return n4;
526 else if ( select == 5 )
return n5;
527 else if ( select == 6 )
return n6;
531 int size=_houghHitList.size();
532 int n0,
n1,
n2,n3,n4,n5,n6;
533 n0=
n1=
n2=n3=n4=n5=n6=0;
534 for(
int i=0;i<size;i++){
535 int cir= _houghHitList[i].getCirList();
536 int type = _houghHitList[i].getSlayerType();
537 int style= _houghHitList[i].getStyle();
539 if(
type!=0 && style == 1 )
n1++;
540 if(
type!=0 && style == 2 )
n2++;
541 if(_houghHitList[i].getDetectorType()==
MDC){
542 int index = _houghHitList[i].digi()->getTrackIndex();
543 if(
type!=0 && index < 0 ) n3++;
544 if(
type!=0 && index >=0 && cir<=1 && style==0) n4++;
545 if(
type!=0 && (index <0 || cir>1) ) n5++;
546 if(
type!=0 && index >=0 && cir==0 && style==0) n6++;
549 if( select == 0 )
return n0;
550 else if( select == 1 )
return n1;
551 else if( select == 2 )
return n2;
552 else if( select == 3 )
return n3;
553 else if( select == 4 )
return n4;
554 else if( select == 5 )
return n5;
555 else if( select == 6 )
return n6;
ObjectVector< RecCgemCluster > RecCgemClusterCol
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
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)