1#include "MdcHoughFinder/MdcHoughFinder.h"
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/SmartDataPtr.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/PropertyMgr.h"
8#include "GaudiKernel/IService.h"
9#include "EventModel/EventHeader.h"
10#include "McTruth/DecayMode.h"
11#include "McTruth/McParticle.h"
12#include "McTruth/MdcMcHit.h"
13#include "RawDataProviderSvc/IRawDataProviderSvc.h"
14#include "RawDataProviderSvc/RawDataProviderSvc.h"
15#include "MdcRawEvent/MdcDigi.h"
16#include "Identifier/Identifier.h"
17#include "Identifier/MdcID.h"
18#include "MdcGeomSvc/IMdcGeomSvc.h"
19#include "MdcGeomSvc/MdcGeoWire.h"
20#include "MdcGeomSvc/MdcGeoLayer.h"
27#include "EvTimeEvent/RecEsTime.h"
28#include "MdcCalibFunSvc/IMdcCalibFunSvc.h"
29#include "RawDataProviderSvc/MdcRawDataProvider.h"
30#include "TrkBase/TrkFit.h"
31#include "TrkBase/TrkHitList.h"
32#include "TrkBase/TrkExchangePar.h"
33#include "TrkFitter/TrkHelixMaker.h"
34#include "TrkFitter/TrkCircleMaker.h"
35#include "TrkFitter/TrkLineMaker.h"
36#include "TrkFitter/TrkHelixFitter.h"
37#include "MdcxReco/Mdcxprobab.h"
38#include "MdcData/MdcHit.h"
39#include "MdcData/MdcRecoHitOnTrack.h"
40#include "MdcTrkRecon/MdcTrack.h"
41#include "MdcPrintSvc/IMdcPrintSvc.h"
42#include "MdcGeom/EntranceAngle.h"
43#include "TrackUtil/Helix.h"
44#include "GaudiKernel/IPartPropSvc.h"
45#include "MdcRecoUtil/Pdt.h"
46#include "RawEvent/RawDataUtil.h"
57 Algorithm(name, pSvcLocator)
60 declareProperty(
"trackNumMc", m_trackNum_Mc_set=1);
61 declareProperty(
"method", m_method=0);
62 declareProperty(
"debug", m_debug = 0);
63 declareProperty(
"data", m_data= 0);
64 declareProperty(
"binx", m_binx= 100);
65 declareProperty(
"biny", m_biny= 100);
66 declareProperty(
"peakCellNum", m_peakCellNum);
67 declareProperty(
"ndev", m_ndev= 3);
68 declareProperty(
"f_pro", m_fpro= 0.8);
69 declareProperty(
"f_hit_pro", m_hit_pro= 0.8);
71 declareProperty(
"pdtFile", m_pdtFile =
"pdt.table");
72 declareProperty(
"pickHits", m_pickHits =
true);
73 declareProperty(
"pid", m_pid = 0);
75 declareProperty(
"combineTracking",m_combineTracking =
true);
76 declareProperty(
"getDigiFlag", m_getDigiFlag = 0);
77 declareProperty(
"maxMdcDigi", m_maxMdcDigi = 0);
78 declareProperty(
"keepBadTdc", m_keepBadTdc = 0);
79 declareProperty(
"dropHot", m_dropHot= 0);
80 declareProperty(
"keepUnmatch", m_keepUnmatch = 0);
81 declareProperty(
"minMdcDigi", m_minMdcDigi = 0);
89 if(NULL == m_gm)
return StatusCode::FAILURE;
92 return StatusCode::SUCCESS;
98 MsgStream log(
msgSvc(), name());
99 log << MSG::INFO <<
"in initialize()" << endreq;
106 IPartPropSvc* p_PartPropSvc;
107 static const bool CREATEIFNOTTHERE(
true);
108 sc = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
109 if (!sc.isSuccess() || 0 == p_PartPropSvc) {
110 log << MSG::ERROR <<
" Could not initialize PartPropSvc" << endreq;
113 m_particleTable = p_PartPropSvc->PDT();
117 sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
119 if ( sc.isFailure() ){
120 log << MSG::FATAL << name()<<
" Could not load RawDataProviderSvc!" << endreq;
121 return StatusCode::FAILURE;
127 sc = service (
"MdcGeomSvc", imdcGeomSvc);
128 m_mdcGeomSvc =
dynamic_cast<MdcGeomSvc*
> (imdcGeomSvc);
129 if ( sc.isFailure() ){
130 log << MSG::FATAL <<
"Could not load MdcGeoSvc!" << endreq;
131 return StatusCode::FAILURE;
134 sc = service (
"MagneticFieldSvc",m_pIMF);
135 if(sc!=StatusCode::SUCCESS) {
136 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
138 m_bfield =
new BField(m_pIMF);
139 log << MSG::INFO <<
"field z = "<<m_bfield->
bFieldNominal()<< endreq;
147 sc = service (
"MdcCalibFunSvc", imdcCalibSvc);
149 if ( sc.isFailure() ){
150 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endreq;
151 return StatusCode::FAILURE;
155 NTuplePtr nt(
ntupleSvc(),
"MdcHoughFinder/hit");
159 ntuplehit =
ntupleSvc()->book(
"MdcHoughFinder/hit", CLID_ColumnWiseTuple,
"hit");
161 ntuplehit->addItem(
"eventNum", m_eventNum);
162 ntuplehit->addItem(
"runNum", m_runNum);
163 ntuplehit->addItem(
"costaCut", m_cosCut);
172 ntuplehit->addItem(
"nHitMc", m_nHit_Mc,0, 6796);
173 ntuplehit->addItem(
"layerMc", m_nHit_Mc, m_layer_Mc);
174 ntuplehit->addItem(
"cellMc", m_nHit_Mc, m_cell_Mc);
177 ntuplehit->addItem(
"nHit", m_nHit,0, 6796);
178 ntuplehit->addItem(
"layerNhit", 43, m_layerNhit);
180 ntuplehit->addItem(
"nCross", m_nCross,0, 125000);
181 ntuplehit->addItem(
"rho", m_nCross, m_rho);
182 ntuplehit->addItem(
"theta", m_nCross, m_theta);
184 ntuplehit->addItem(
"hitSignal", m_nHit, m_hitSignal);
185 ntuplehit->addItem(
"layer", m_nHit, m_layer);
186 ntuplehit->addItem(
"cell", m_nHit, m_cell);
187 ntuplehit->addItem(
"x_east", m_nHit, m_x_east);
188 ntuplehit->addItem(
"y_east", m_nHit, m_y_east);
189 ntuplehit->addItem(
"z_east", m_nHit, m_z_east);
190 ntuplehit->addItem(
"x_west", m_nHit, m_x_west);
191 ntuplehit->addItem(
"y_west", m_nHit, m_y_west);
192 ntuplehit->addItem(
"z_west", m_nHit, m_z_west);
193 ntuplehit->addItem(
"x", m_nHit, m_x);
194 ntuplehit->addItem(
"y", m_nHit, m_y);
195 ntuplehit->addItem(
"z", m_nHit, m_z);
196 ntuplehit->addItem(
"u", m_nHit, m_u);
197 ntuplehit->addItem(
"v", m_nHit, m_v);
198 ntuplehit->addItem(
"p", m_nHit, m_p);
199 ntuplehit->addItem(
"slant", m_nHit, m_slant);
202 ntuplehit->addItem(
"maxCount", m_maxCount);
204 ntuplehit->addItem(
"peakColumn", m_npeak,0,100);
205 ntuplehit->addItem(
"peakWidth", m_npeak, m_peakWidth);
206 ntuplehit->addItem(
"peakHigh", m_npeak, m_peakHigh);
207 ntuplehit->addItem(
"peakArea", m_npeak, m_peakArea);
208 ntuplehit->addItem(
"peakAreaLeast", m_areaLeast);
209 ntuplehit->addItem(
"peakAreaLeastNum", m_areaLeastNum);
210 ntuplehit->addItem(
"peakHitSelect", m_areaSelectHit);
211 ntuplehit->addItem(
"peakHitSelectSignal", m_areaSelectHit_signal);
215 ntuplehit->addItem(
"circleCenterX", m_x_circle);
216 ntuplehit->addItem(
"circleCenterY", m_y_circle);
217 ntuplehit->addItem(
"circleR", m_r);
220 ntuplehit->addItem(
"zStereoNum", m_zStereoNum,0,1000);
221 ntuplehit->addItem(
"zStereo", m_zStereoNum, m_zStereo );
222 ntuplehit->addItem(
"l", m_zStereoNum, m_l);
224 ntuplehit->addItem(
"trackNum_Mc", m_trackNum_Mc, 0,100);
225 ntuplehit->addItem(
"trackNum", m_trackNum, 0,100);
226 ntuplehit->addItem(
"d0", m_trackNum, m_d0);
227 ntuplehit->addItem(
"phi0", m_trackNum, m_phi0);
228 ntuplehit->addItem(
"omega", m_trackNum, m_omega);
229 ntuplehit->addItem(
"z0", m_trackNum, m_z0);
230 ntuplehit->addItem(
"tanl", m_trackNum, m_tanl);
232 ntuplehit->addItem(
"pt_rec", m_trackNum, m_pt);
233 ntuplehit->addItem(
"pt2_rec", m_trackNum, m_pt2);
234 ntuplehit->addItem(
"pz_rec", m_trackNum, m_pz);
235 ntuplehit->addItem(
"p_rec", m_trackNum, m_pxyz);
237 ntuplehit->addItem(
"nHitSignal", m_nHitSignal);
238 ntuplehit->addItem(
"nHitAxialSignal", m_nHitAxialSignal);
239 ntuplehit->addItem(
"nHitSignal_select", m_trackNum, m_nHitSignal_select);
240 ntuplehit->addItem(
"nHitAxialSignal_selcet", m_trackNum, m_nHitAxialSignal_select);
241 ntuplehit->addItem(
"fitFailure", m_trackNum, m_nFitFailure);
242 ntuplehit->addItem(
"nFit", m_trackNum, m_2d_nFit);
243 ntuplehit->addItem(
"3dnFit", m_trackNum, m_3d_nFit);
244 ntuplehit->addItem(
"nHitAxial", m_nHitAxial);
245 ntuplehit->addItem(
"nFitSucess", m_nFitSucess);
249 ntuplehit->addItem(
"pidTruth", m_pidTruth);
250 ntuplehit->addItem(
"costaTruth", m_costaTruth);
251 ntuplehit->addItem(
"phiTruth", m_phi0Truth);
252 ntuplehit->addItem(
"drTruth", m_drTruth);
253 ntuplehit->addItem(
"dzTruth", m_dzTruth);
254 ntuplehit->addItem(
"ptTruth", m_ptTruth);
255 ntuplehit->addItem(
"pzTruth", m_pzTruth);
256 ntuplehit->addItem(
"pTruth", m_pTruth);
257 ntuplehit->addItem(
"qTruth", m_qTruth);
260 }
else { log << MSG::ERROR <<
"Cannot book tuple MdcHoughFinder/hit" << endmsg;
261 return StatusCode::FAILURE;
268 return StatusCode::SUCCESS;
277 MsgStream log(
msgSvc(), name());
278 log << MSG::INFO <<
"in execute()" << endreq;
281 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
283 log << MSG::WARNING<<
"Could not retrieve RecEsTimeCol , use t0=0" << endreq;
286 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
287 if (iter_evt != evTimeCol->end()){
288 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
295 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
297 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
298 return( StatusCode::FAILURE);
302 DataObject *aTrackCol;
303 DataObject *aRecHitCol;
304 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
305 if(!m_combineTracking){
306 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
307 if(aTrackCol != NULL) {
308 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
309 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
311 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
312 if(aRecHitCol != NULL) {
313 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
314 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
319 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
325 if(!sc.isSuccess()) {
326 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
327 return StatusCode::FAILURE;
330 int nTdsTk = (int) trackList->size();
334 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
340 if(!sc.isSuccess()) {
341 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
342 return StatusCode::FAILURE;
361 t_eventNum=eventHeader->eventNumber();
362 t_runNum=eventHeader->runNumber();
363 m_eventNum=t_eventNum;
365 log << MSG::INFO <<
"MdcHoughFinder: retrieved event: " << eventHeader->eventNumber() <<
" run: " << eventHeader->runNumber() << endreq;
368 int mc_particle=GetMcInfo();
371 if(
abs(m_costaTruth)<=0.83){m_cosCut=1;}
382 vector<double> vec_u;
383 vector<double> vec_v;
384 vector<double> vec_p;
385 vector<double> vec_x_east;
386 vector<double> vec_y_east;
387 vector<double> vec_z_east;
388 vector<double> vec_x_west;
389 vector<double> vec_y_west;
390 vector<double> vec_z_west;
391 vector<double> vec_z_Mc;
392 vector<double> vec_x;
393 vector<double> vec_y;
394 vector<double> vec_z;
395 vector<int> vec_layer;
396 vector<int> vec_wire;
397 vector<int> vec_slant;
398 vector<double> vec_zStereo;
401 vector<int> vec_layer_Mc;
402 vector<int> vec_wire_Mc;
411 SmartDataPtr<Event::MdcMcHitCol> mcMdcMcHitCol(eventSvc(),
"/Event/MC/MdcMcHitCol");
412 if (!mcMdcMcHitCol) {
413 log << MSG::INFO <<
"Could not find MdcMcHit" << endreq;
415 Event::MdcMcHitCol::iterator iterMcHit = mcMdcMcHitCol->begin();
417 for(; iterMcHit != mcMdcMcHitCol->end(); ++iterMcHit,digiId_Mc++) {
422 vec_layer_Mc.push_back(layerId_Mc);
423 vec_wire_Mc.push_back(wireId_Mc);
428 m_layer_Mc[digiId_Mc]=layerId_Mc;
429 m_cell_Mc[digiId_Mc]=wireId_Mc;
432 if ((layerId_Mc>=8&&layerId_Mc<=19)||(layerId_Mc>=36)) {
434 if(m_debug>0) {cout<<
"("<<layerId_Mc<<
","<<wireId_Mc<<
")"<<
"nHitAxial_Mc: "<<nHitAxial_Mc<<endl;}
435 m_layer[digiId_Mc]=layerId_Mc;
436 m_cell[digiId_Mc]=wireId_Mc;
437 const MdcGeoWire *geowir =m_mdcGeomSvc->
Wire(layerId_Mc,wireId_Mc);
441 m_x_east[digiId_Mc]=eastP.x();
442 m_y_east[digiId_Mc]=eastP.y();
443 m_z_east[digiId_Mc]=eastP.z();
444 m_x_west[digiId_Mc]=westP.x();
445 m_y_west[digiId_Mc]=westP.y();
446 m_z_west[digiId_Mc]=westP.z();
448 vec_x_east.push_back(eastP.x());
449 vec_y_east.push_back(eastP.y());
450 vec_z_east.push_back(eastP.z());
451 vec_x_west.push_back(westP.x());
452 vec_y_west.push_back(westP.y());
453 vec_z_west.push_back(westP.z());
455 double x = (*iterMcHit)->getPositionX()/10.;
456 double y = (*iterMcHit)->getPositionY()/10.;
457 double z = (*iterMcHit)->getPositionZ()/10.;
459 double u=CFtrans(
x,y);
460 double v=CFtrans(y,
x);
461 double p=sqrt(u*u+
v*
v);
477 int layer= layerId_Mc;
478 vec_slant.push_back(SlantId(layer));
479 m_slant[digiId_Mc]=SlantId(layer);
481 {cout<<
"layer: "<<layerId_Mc<<
"wire: "<<wireId_Mc<<
"x_east: "<<m_x_east[digiId_Mc]<<
"y_east: "<<m_y_east[digiId_Mc]<<endl;}
488 if(m_data==0) {m_nHit=digiId_Mc;}
505 vector<int> vec_hitSignal;
506 vector<int> vec_track_index;
507 int track_index_max=0;
508 uint32_t getDigiFlag = 0;
514 cout<<
"MdcDigiVec: "<<mdcDigiVec.size()<<endl;
515 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
521 int nHitAxialSignal=0;
523 for (;iter1 != mdcDigiVec.end(); iter1++, digiId++) {
524 int track_index=(*iter1)->getTrackIndex();
526 if(track_index>=1000) track_index-=1000;
527 vec_track_index.push_back(track_index);
530 m_hitSignal[digiId]=1;
540 if ((layerId>=8&&layerId<=19)||(layerId>=36)) {
542 if (((layerId>=8&&layerId<=19)||(layerId>=36))&&track_index>=0) {
545 vec_layer.push_back(layerId);
546 vec_wire.push_back(wireId);
548 nHitLayer[layerId]++;
549 m_layerNhit[layerId]=nHitLayer[layerId];
555 vec_x_east.push_back(eastP.x());
556 vec_y_east.push_back(eastP.y());
557 vec_z_east.push_back(eastP.z());
558 vec_x_west.push_back(westP.x());
559 vec_y_west.push_back(westP.y());
560 vec_z_west.push_back(westP.z());
562 m_x_east[digiId]=eastP.x();
563 m_y_east[digiId]=eastP.y();
564 m_z_east[digiId]=eastP.z();
565 m_x_west[digiId]=westP.x();
566 m_y_west[digiId]=westP.y();
567 m_z_west[digiId]=westP.z();
568 if(m_debug>0) {cout<<
"event: "<<t_eventNum<<
" "<<
"layer: "<<layerId<<
" "<<
"wireId: "<<wireId<<
" "<<
"zeast: "<<vec_z_east.at(digiId)<<
" "<<
"zwest: "<<vec_z_west.at(digiId)<<
" "<<endl;}
570 double x =(eastP.x()+westP.x())/2.;
571 double y =(eastP.y()+westP.y())/2.;
572 vec_x.push_back((vec_x_east[digiId]+vec_x_west[digiId])/2);
573 vec_y.push_back((vec_y_east[digiId]+vec_y_west[digiId])/2);
574 m_x[digiId]=(vec_x_east[digiId]+vec_x_west[digiId])/2;
575 m_y[digiId]=(vec_y_east[digiId]+vec_y_west[digiId])/2;
576 double u=CFtrans(
x,y);
577 double v=CFtrans(y,
x);
580 vec_p.push_back(sqrt(u*u+
v*
v));
585 m_p[digiId]=sqrt(u*u+
v*
v);
587 m_layer[digiId]=geowir->
Layer();
588 m_cell[digiId]=geowir->
Cell();
590 vec_slant.push_back(SlantId(layer));
591 m_slant[digiId]=SlantId(layer);
596 for(
int i=0;i<digiId;i++){
597 if(track_index_max<=vec_track_index[i]) track_index_max=vec_track_index[i];
600 m_trackNum_Mc=track_index_max;
602 vector< vector <int> > mc_track_hit(track_index_max,vector<int>() );
603 for(
int i=0;i<track_index_max;i++){
604 for(
int j=0;j<digiId;j++){
605 if(vec_track_index[j]==i) mc_track_hit[i].push_back(j);
609 track_index_max=m_trackNum_Mc_set;
620 m_nHitAxial=nHitAxial;
623 m_nHitSignal=nHitSignal;
624 m_nHitAxialSignal=nHitAxialSignal;
626 cout<<
"hit number: "<<digiId<<endl;
630 for(
int i =0;i<m_nHit;i++){
631 if(t_maxP<vec_p[i]) {t_maxP=vec_p[i];}
634 for(
int i =0;i<
m_nHit;i++){
635 if(t_minP>vec_p[i]) {t_minP=vec_p[i];}
654 double binwidth=
M_PI/binX;
655 double binhigh=2*t_maxP/binY;
656 TH2D *h1=
new TH2D(
"h1",
"h1",binX,0,
M_PI,binY,-t_maxP,t_maxP);
660 vector<double> vec_rho;
661 vector<double> vec_theta;
662 vector< vector<int> > vec_hitNum(2,vector<int>());
663 int numCross=(int)(nhit*(nhit-1)/2);
665 RhoTheta(numCross,nhit,vec_u,vec_v,vec_rho,vec_theta,vec_hitNum);
666 FillRhoTheta(h1,vec_theta,vec_rho,numCross);
669 vector< vector< vector<int> > > vec_selectNum(binX,vector< vector<int> >(binY,vector<int>() ) );
671 FillHist(h1,vec_u,vec_v,nhit,vec_selectNum);
675 vector<bool> vec_truthHit(nhit,
false);
676 vector< vector <int> > countij(binX,vector <int> (binY,0) );
678 vector< vector< vector<int> > > vec_selectHit(binX,vector< vector<int> >(binY,vector<int>() ) );
680 FillCells(h1,nhit,binX,binY,vec_u,vec_v,vec_layer,vec_wire,countij,vec_selectNum,vec_selectHit);
701 for(
int i=0;i<binX;i++){
702 for(
int j=0;j<binY;j++){
703 int count=h1->GetBinContent(i+1,j+1);
704 if(max_count<count) {
777 // int columnx_split=(int)(column/10)*100+100;
778 // int columny_split=(int)(column%10)*100+100;
779 // //cout<<"column: "<<column<<" "<<"("<<columnx_split<<","<<columny_split<<")"<<peakArea[column]<<endl;
783 // double area_least=peakArea[0];
784 // for(int i=0;i<100;i++){
785 // if(area_least>peakArea[i]){
786 // area_least=peakArea[i];
789 // int num_area_least=0;
790 // for(int i=0;i<100;i++){
791 // if(area_least==peakArea[i]){
795 // int binx_split=(int)(num_area_least/10)*100+100;
796 // int biny_split=(int)(num_area_least%10)*100+100;
797 // m_areaLeast=area_least;
798 // m_areaLeastNum=num_area_least;
799 //cout<<"the max peakArea: "<<num_area_least<<"("<<binx_split<<","<<biny_split<<")"<<"peakarea is : "<<area_least<<endl;
809 for(
int i=0;i<binX;i++){
810 for(
int j=0;j<binY;j++){
811 int count=h1->GetBinContent(i+1,j+1);
821 cout<<
"count_use: "<<count_use<<endl;
822 double aver=sum/count_use;
823 double dev=sqrt(sum2/count_use-aver*aver);
824 int min_counts=(int)(aver+f_n*dev);
825 cout<<
"aver: "<<aver<<
" "<<
"dev: "<<dev<<
" min: "<<min_counts<<endl;
828 vector< vector <int> > hough_trans_CS(binX,vector <int> (binY,0) );
829 vector< vector <int> > hough_trans_CS_peak(binX,vector <int> (binY,0) );
832 for(
int i=0;i<binX;i++){
833 for(
int j=0;j<binY;j++){
834 hough_trans_CS[i][j]=h1->GetBinContent(i+1,j+1);
839 for (
int r=0; r<binY; r++) {
840 for (
int a=0; a<binX; a++) {
842 for (
int ar=a-1; ar<=a+1; ar++) {
843 for (
int rx=r-1; rx<=r+1; rx++) {
845 if (ar<0) { ax=ar+binX; }
846 else if (ar>=binX) { ax=ar-binX; }
848 if ( (ax!=a || rx!=r) && rx>=0 && rx<binY) {
849 if (hough_trans_CS[ax][rx]>max_around) { max_around=hough_trans_CS[ax][rx]; }
853 if (hough_trans_CS[a][r]<=min_counts) { hough_trans_CS_peak[a][r]=0; }
854 else if (hough_trans_CS[a][r]<max_around) { hough_trans_CS_peak[a][r]=0; }
855 else if (hough_trans_CS[a][r]==max_around) { hough_trans_CS_peak[a][r]=1; }
856 else if (hough_trans_CS[a][r]>max_around) { hough_trans_CS_peak[a][r]=2; }
857 if(hough_trans_CS_peak[a][r]!=0) {
867 for (
int r=0; r<binY; r++) {
868 for (
int a=0; a<binX; a++) {
869 if (hough_trans_CS_peak[a][r]==1) {
870 hough_trans_CS_peak[a][r]=2;
871 for (
int ar=a-1; ar<=a+1; ar++) {
872 for (
int rx=r-1; rx<=r+1; rx++) {
874 if (ar<0) { ax=ar+binX; }
875 else if (ar>=binX) { ax=ar-binX; }
877 if ( (ax!=a || rx!=r) && rx>=0 && rx<binY) {
878 if (hough_trans_CS_peak[ax][rx]==1) { hough_trans_CS_peak[ax][rx]=0; }
883 if(hough_trans_CS_peak[a][r]!=0) {
896 TH2D *h2 =
new TH2D(
"h2",
"test2",binX,0,3.14,binY,-t_maxP,t_maxP);
897 for(
int i=0;i<binX;i++){
898 for(
int j=0;j<binY;j++){
899 if(hough_trans_CS_peak[i][j]==2){
900 h2->SetBinContent(i+1,j+1,hough_trans_CS[i][j]);
905 vector<int> peakList1[3];
906 for(
int n=0;
n<peak_num_2;
n++){
907 for (
int r=0; r<binY; r++) {
908 for (
int a=0; a<binX; a++) {
909 if (hough_trans_CS_peak[a][r]==2) {
910 peakList1[0].push_back(a+1);
911 peakList1[1].push_back(r+1);
912 peakList1[2].push_back(hough_trans_CS[a][r]);
917 cout<<
"finish peak?"<<endl;
918 if(m_method==0) cout<<
"numCross: "<<numCross<<endl;
920 int npeak1=peak_num_2;
922 for (
int na=0; na<npeak1-1; na++) {
924 for (
int nb=na+1; nb<npeak1; nb++) {
925 if (peakList1[2][n_max]<peakList1[2][nb]) { n_max=nb; }
929 for (
int i=0; i<3; i++) {
930 swap[i]=peakList1[i][na];
931 peakList1[i][na]=peakList1[i][n_max];
932 peakList1[i][n_max]=swap[i];
936 cout<<
"npeak1: "<<npeak1<<endl;
937 for(
int n=0;
n<npeak1;
n++){
938 int bintheta=peakList1[0][
n];
939 int binrho=peakList1[1][
n];
940 int count=peakList1[2][
n];
941 for(
int i=0;i<count;i++){
948 typedef std::map<int, int> M2;
949 typedef std::map<int, M2> M1;
960 vector<bool> peaktrack(npeak1,
true);
964 double peak_cellNum[43];
968 double bin_right[43];
971 double area_left[43];
972 double area_right[43];
974 double area_down[43];
977 for(
int iLayer=0; iLayer<m_gm->
nLayer(); iLayer++){
978 peak_cellNum[iLayer]=m_peakCellNum[iLayer];
979 peakX[iLayer]=peakList1[0][
n];
980 peakY[iLayer]=peakList1[1][
n];
981 bin_left[iLayer]=peakX[iLayer]-peak_cellNum[iLayer];
982 bin_right[iLayer]=peakX[iLayer]+peak_cellNum[iLayer];
983 bin_up[iLayer]=peakY[iLayer]+peak_cellNum[iLayer];
984 bin_down[iLayer]=peakY[iLayer]-peak_cellNum[iLayer];
985 area_left[iLayer]=(bin_left[iLayer]-1)*binwidth;
986 area_right[iLayer]=(bin_right[iLayer])*binwidth;
988 area_down[iLayer]=(bin_down[iLayer]-1)*binhigh-t_maxP;
989 area_up[iLayer]=(bin_up[iLayer])*binhigh-t_maxP;
992 for(
int k=0;k<nhit;k++){
993 int layer=vec_layer[k];
994 double lineLeft=vec_u[k]*
cos(area_left[layer])+vec_v.at(k)*
sin(area_right[layer]);
995 double lineRight=vec_u[k]*
cos(area_left[layer])+vec_v.at(k)*
sin(area_right[layer]);
997 if((lineLeft<area_up[layer])&&(lineLeft>area_down[layer])||(lineRight<area_up[layer])&&(lineRight>area_down[layer])||((lineLeft-area_up[layer])*(area_down[layer]-lineRight)>0)){
1004 hit_combine[m][count_peak]=k;
1009 peak_combine_num[m]=count_peak;
1013 for(
int i=
n+1;i<npeak1;i++){
1014 if(peaktrack[i]==
false)
continue;
1015 int peaktheta=peakList1[0][i];
1016 int peakrho=peakList1[1][i];
1017 int peakhitNum=peakList1[2][i];
1018 int count_same_hit=0;
1019 for(
int j=0;j<peakhitNum;j++){
1021 for(
int k=0;k<peak_combine_num[m];k++){
1022 if(vec_selectNum[peaktheta-1][peakrho-1][j]==hit_combine[m][k]){
1027 double f_hit=m_hit_pro;
1028 if(count_same_hit>f_hit*peakhitNum){
1032 for(
int i=
n+1;i<npeak1;i++){
1033 if(peaktrack[i]==
true){
1039 cout<<
"peak_m: "<<m+1<<endl;
1044 for(
int i=0;i<npeak1;i++){
1045 cout<<
"track"<<i<<
": "<<
"("<<peakList1[0][i]<<
","<<peakList1[1][i]<<
","<<peakList1[2][i]<<
")"<<
" "<<
"truth: "<<peaktrack[i]<<endl;
1046 if(peaktrack[i]==
true){
1050 for(
int i=0;i<peak_track;i++){
1051 for(
int j =0;j<peak_combine_num[i];j++){
1052 int hit_number=hit_combine[i][j];
1053 cout<<
" peak "<<i<<
" has select hits: "<<vec_layer[hit_number]<<
" "<<vec_wire[hit_number]<<endl;
1055 cout<<
"has collect :"<<peak_combine_num[i]<<
" hits "<<endl;
1057 cout<<
"event"<<t_eventNum<<
": "<<
"has found: "<<peak_track<<
" track."<<endl;
1058 m_trackNum=peak_track;
1064 vector< vector<int> > rec_mc_num(peak_track,vector<int>(track_index_max,0) );
1065 vector< vector<int> > rec_mc_num_axial(peak_track,vector<int>(track_index_max,0) );
1066 if(track_index_max!=peak_track) cout<<
"not match track number !"<<endl;
1067 for(
int mc_track_num=0;mc_track_num<track_index_max;mc_track_num++){
1068 for(
int i=0;i<peak_track;i++){
1069 for(
int j=0;j<peak_combine_num[i];j++){
1070 for(
int k=0;k<mc_track_hit[mc_track_num].size();k++){
1071 if(hit_combine[i][j]==mc_track_hit[mc_track_num][k]){
1072 rec_mc_num[i][mc_track_num]++;
1073 int hit_num=mc_track_hit[mc_track_num][k];
1074 if(vec_slant[hit_num]==0) rec_mc_num_axial[i][mc_track_num]++;
1080 vector<int> rec_mc(peak_track,999);
1081 for(
int i=0;i<peak_track;i++){
1082 for(
int mc_track_num=0;mc_track_num<track_index_max;mc_track_num++){
1083 if(rec_mc_num[i][mc_track_num]>0.5*peak_combine_num[i]) rec_mc[i]=mc_track_num;
1084 cout<<
"trackrec: "<<i<<
" trackmc: "<<mc_track_num<<
" "<<rec_mc_num[i][mc_track_num]<<
" "<<peak_combine_num[i]<<endl;
1087 for(
int i=0;i<peak_track;i++){
1088 cout<<
"rec :"<<i<<
"belong to mc track: "<<rec_mc[i]<<endl;
1090 for(
int i=0;i<peak_track;i++){
1091 int mc_track_num=rec_mc[i];
1092 if(mc_track_num!=999) {
1093 cout<<
"debug mc_track_num: "<<mc_track_num<<endl;
1094 m_nHitSignal_select[i]=rec_mc_num[i][mc_track_num];
1095 m_nHitAxialSignal_select[i]=rec_mc_num_axial[i][mc_track_num];
1096 cout<<
"m_nHitSignal_select: "<<m_nHitSignal_select[i]<<endl;
1351for(track_fit=0;track_fit<peak_track;track_fit++){
1352 for(
int i=0;i<nhit;i++){
1353 vec_truthHit[i]=
false;
1355 cout<<
"track: "<<track_fit<<
" has select: "<<peak_combine_num[track_fit]<<
" hit ."<<endl;
1356 for(
int i=0;i<peak_combine_num[track_fit];i++){
1357 int hitNum=hit_combine[track_fit][i];
1358 vec_truthHit[hitNum]=
true;
1361 int nHitAxialSelect_temp=10;
1362 int leastSquare=LeastSquare(nhit,nHitAxialSelect_temp,vec_x,vec_y,vec_slant,vec_layer,vec_truthHit,d0,phi0,omega);
1370 bool permitFlips =
true;
1371 bool lPickHits = m_pickHits;
1374 int nDigi = digiToHots(newTrack,vec_truthHit);
1382 bool fitSuccess =
false;
1384 if (!newFit || (newFit->
nActive()<3)) {
1386 cout <<
"evt "<<t_eventNum<<
" global fit failed ";
1387 if(newFit) cout <<
" nAct "<<newFit->
nActive();
1396 if(m_debug>0) newTrack->
print(std::cout);
1400 vector<int> nfit2d(peak_track,0);
1401 if(m_debug>0) cout<<
" hot list:"<<endl;
1404 nfit2d[track_fit]++;
1405 cout <<
"(" <<((
MdcHit*)(hotIter->hit()))->layernumber()
1406 <<
","<<((
MdcHit*)(hotIter->hit()))->wirenumber()
1407 <<
":"<<hotIter->isActive()<<
") ";
1411 m_2d_nFit[track_fit]=nfit2d[track_fit];
1427 r_temp=1./-par.
omega();
1431 m_pt[track_fit]=r_temp/333.567;
1432 cout<<
"pt_rec: "<<m_pt[track_fit]<<endl;
1435 m_nFitFailure[track_fit]=2;
1439 int z_stereoNum= Zposition(nhit,vec_slant,x_cirtemp,y_cirtemp,r_temp,vec_x_east,vec_x_west,vec_y_east, vec_y_west,vec_z_east,vec_z_west, vec_layer, vec_wire,vec_z,vec_zStereo,l,vec_truthHit);
1443 m_zStereoNum=z_stereoNum;
1444 for(
int i=0;i<z_stereoNum;i++){
1446 m_zStereoNum=z_stereoNum;
1447 m_zStereo[i]=vec_zStereo[i];
1450 if(m_debug>0) cout<<
" l: "<<m_l[i]<<
" "<<
"z: "<<vec_zStereo[i]<<endl;
1454 Linefit(z_stereoNum,vec_zStereo,l,tanl,z0);
1456 cout<<
"tanl: "<<tanl<<endl;
1457 cout<<
"z0: "<<z0<<endl;
1460 cout<<
"tanltruth: "<<tanl<<endl;
1461 cout<<
"z0truth: "<<z0<<endl;
1469 lPickHits = m_pickHits;
1472 int nDigi2 = digiToHots2(newTrack2,vec_truthHit);
1483 if (!newFit2 || (newFit2->
nActive()<5)) {
1486 cout <<
"evt "<<t_eventNum<<
" global fit failed ";
1487 if(newFit2) cout <<
" nAct "<<newFit2->
nActive();
1496 int tkId = nTdsTk + track_fit;
1497 mdcTrack->
storeTrack(tkId, trackList, hitList, tkStat);
1502 if(m_debug>0) newTrack2->
print(std::cout);
1506 vector<int> nfit3d(peak_track,0);
1507 if(m_debug>0) cout<<
" hot list:"<<endl;
1510 nfit3d[track_fit]++;
1511 cout <<
"(" <<((
MdcHit*)(hotIter2->hit()))->layernumber()
1512 <<
","<<((
MdcHit*)(hotIter2->hit()))->wirenumber()
1513 <<
":"<<hotIter2->isActive()<<
") ";
1517 m_3d_nFit[track_fit]=nfit3d[track_fit];
1530 r_temp=1./-par2.
omega();
1534 m_d0[track_fit]=par2.
d0();
1535 m_phi0[track_fit]=par2.
phi0();
1536 m_omega[track_fit]=par2.
omega();
1537 m_z0[track_fit]=par2.
z0();
1538 m_tanl[track_fit]=par2.
tanDip();
1540 double pxy=r_temp/333.567;
1541 double pz=pxy*par2.
tanDip();
1542 double pxyz=sqrt(pxy*pxy+pz*pz);
1543 m_pt2[track_fit]=pxy;
1544 m_pz[track_fit]=pxy*par2.
tanDip();
1545 m_pxyz[track_fit]=pxyz;
1546 cout<<
"track"<<track_fit<<
": "<<
"pt_rec2: "<<m_pt2[track_fit]<<endl;
1547 cout<<
"eventNum: "<<t_eventNum<<
" "<<
"track"<<track_fit<<
": "<<
"pz_rec: "<<m_pz[track_fit]<<endl;
1550 m_nFitFailure[track_fit]=3;
1587m_nFitSucess=nFitSucess;
1588cout<<
" Hough finder find "<<nFitSucess<<
" tot "<<nTdsTk<< endl;
1592cout<<
"break: ????"<<endl;
1594cout<<
"finish event "<<t_eventNum<<endl;
1597return StatusCode::SUCCESS;
1602 MsgStream log(
msgSvc(), name());
1603 log << MSG::INFO <<
"in finalize()" << endreq;
1604 return StatusCode::SUCCESS;
1606int MdcHoughFinder::digiToHots(
TrkRecoTrk* newTrack,vector<bool> vec_truthHit){
1624 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
1625 for (;iter1 != mdcDigiVec.end(); iter1++, digiId++) {
1628 if(vec_truthHit[digiId]==
false)
continue;
1629 const MdcDigi* aDigi = *iter1;
1635 if ((layer>=0&&layer<=7)||(layer>=20&&layer<=35)) {
continue;}
1639 if(m_debug>0) std::cout<<
" ("<<layer<<
","<<wire<<
") "<<std::endl;
1652 double fltLen = m_gm->
Layer(layer)->
rMid();
1657 if(m_debug>2) std::cout<<
" ("<<layer<<
","<<wire<<
",rt "<<hit->
rawTime()<<
",dt "<<hit->
driftTime(m_bunchT0,0)<<
") T0 " << m_mdcCalibFunSvc->
getT0(layer,wire) <<
" timewalk "<< m_mdcCalibFunSvc->
getTimeWalk(layer, aDigi->
getChargeChannel())<<endl;
1659 if(hit->
driftDist(m_bunchT0,0)>1.2)
continue;
1663 if(m_debug>1) std::cout<<std::endl;
1664 return trkHitList->
nHit();
1667double MdcHoughFinder::CFtrans(
double x,
double y){
1678int MdcHoughFinder::SlantId(
int layer){
1679 if ((layer>=0&&layer<=7)||(layer>=20&&layer<=35)) {
1680 if ((layer>=0&&layer<=3)||(layer>=20&&layer<=23)||(layer>=28&&layer<=31)){
1692int MdcHoughFinder::GetMcInfo(){
1694 MsgStream log(
msgSvc(), name());
1696 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
1697 if (!mcParticleCol) {
1698 log << MSG::ERROR <<
"Could not find McParticle" << endreq;
1703 int t_pidTruth = -999;
1704 int t_McTkId = -999;
1707 McParticleCol::iterator iter_mc = mcParticleCol->begin();
1708 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
1709 if(!(*iter_mc)->primaryParticle())
continue;
1710 t_pidTruth = (*iter_mc)->particleProperty();
1712 if(m_debug>2) cout<<
"tk "<<itk<<
" pid="<< t_pidTruth<< endl;
1713 if((m_pid!=0) && (t_pidTruth != m_pid)){
continue; }
1719 int pid = t_pidTruth;
1721 log << MSG::WARNING <<
"Wrong particle id" <<endreq;
1724 IPartPropSvc* p_PartPropSvc;
1725 static const bool CREATEIFNOTTHERE(
true);
1726 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
1727 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
1728 std::cout<<
" Could not initialize Particle Properties Service" << std::endl;
1730 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
1732 if( p_particleTable->particle(pid) ){
1733 name = p_particleTable->particle(pid)->name();
1734 t_qTruth = p_particleTable->particle(pid)->charge();
1735 }
else if( p_particleTable->particle(-pid) ){
1736 name =
"anti " + p_particleTable->particle(-pid)->name();
1737 t_qTruth = (-1)*p_particleTable->particle(-pid)->charge();
1739 if(m_debug>2) std::cout <<
" particle "<<name<<
" charge= "<<t_qTruth<<std::endl;
1742 t_McTkId = (*iter_mc)->trackIndex();
1744 double px = (*iter_mc)->initialFourMomentum().px();
1745 double py = (*iter_mc)->initialFourMomentum().py();
1746 double pz = (*iter_mc)->initialFourMomentum().pz();
1750 mchelix =
new Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);
1754 std::cout<<
"Truth tk "<<itk<<
" pid "<<pid<<
" charge "<<t_qTruth
1755 <<
" helix "<< mchelix->
a()<<
" p "<<mchelix->
momentum(0.)<<std::endl;
1761 std::cout<<
"WARNING run "<<t_runNum<<
" evt "<<t_eventNum<<
" not single event. nTrkMc="<<t_nTrkMC<<std::endl;
1764 if(m_debug>2) std::cout<<
"nTrkMc=1"<<std::endl;
1768 m_pidTruth = t_pidTruth;
1769 m_costaTruth = mchelix->
cosTheta();
1770 m_phi0Truth = mchelix->
phi0();
1771 m_drTruth = mchelix->
dr();
1772 m_dzTruth = mchelix->
dz();
1773 m_ptTruth = mchelix->
pt();
1774 m_pTruth = mchelix->
momentum(0.).mag();
1775 m_qTruth = t_qTruth;
1776 dz_mc =mchelix->
dz();
1777 tanl_mc =mchelix->
tanl();
1782int MdcHoughFinder::LeastSquare(
int n,
int nHitAxialSelect,vector<double> vec_x,vector<double> vec_y, vector<int> vec_slant,vector<int> vec_layer,vector<bool> vec_truthHit,
double &d0,
double &phi0,
double &omega){
1803 double x_aver,y_aver,r2;
1804 for(
int i=0;i<
n;i++){
1805 if(vec_truthHit[i]==
false)
continue;
1806 if(vec_slant[i]!=0)
continue;
1808 x_sum=x_sum+vec_x[i];
1809 y_sum=y_sum+vec_y[i];
1810 x2_sum=x2_sum+vec_x[i]*vec_x[i];
1811 y2_sum=y2_sum+vec_y[i]*vec_y[i];
1812 x3_sum=x3_sum+vec_x[i]*vec_x[i]*vec_x[i];
1813 y3_sum=y3_sum+vec_y[i]*vec_y[i]*vec_y[i];
1814 x2y_sum=x2y_sum+vec_x[i]*vec_x[i]*vec_y[i];
1815 xy2_sum=xy2_sum+vec_x[i]*vec_y[i]*vec_y[i];
1816 xy_sum=xy_sum+vec_x[i]*vec_y[i];
1818 a1=x2_sum-x_sum*x_sum/
n;
1819 a2=xy_sum-x_sum*y_sum/
n;
1821 b2=y2_sum-y_sum*y_sum/
n;
1822 c1=(x3_sum+xy2_sum-x_sum*(x2_sum+y2_sum)/
n)/2.;
1823 c2=(y3_sum+x2y_sum-y_sum*(x2_sum+y2_sum)/
n)/2.;
1828 m_x_circle =(b1*c2-b2*c1)/(b1*b1-a1*b2);
1829 m_y_circle =(b1*c1-a1*c2)/(b1*b1-a1*b2);
1831 double x_cirtemp =(b1*c2-b2*c1)/(b1*b1-a1*b2);
1832 double y_cirtemp =(b1*c1-a1*c2)/(b1*b1-a1*b2);
1834 r2=(x2_sum+y2_sum-2*x_cirtemp*x_sum-2*y_cirtemp*y_sum)/
n+x_cirtemp*x_cirtemp+y_cirtemp*y_cirtemp;
1838 double r_temp=sqrt(r2);
1839 double d0_temp=sqrt(x_cirtemp*x_cirtemp+y_cirtemp*y_cirtemp)-r_temp;
1844 double pt_temp=r_temp/333.567;
1845 cout<<
"pt_temp: "<<pt_temp<<endl;
1851 phi0=atan2(y_cirtemp,x_cirtemp)+
M_PI/2.;
1863 if(m_debug<0)std::cout<<
" before global fit Helix PatPar :"<<d0<<
","<<phi0<<
","<<omega<<
","<<z0<<
","<<tanl<< std::endl;
1868int MdcHoughFinder::Zposition(
int n,vector<int> vec_slant,
double x_cirtemp,
double y_cirtemp,
double r_temp,vector<double> vec_x_east,vector<double> vec_x_west,vector<double> vec_y_east,vector<double> vec_y_west,vector<double> vec_z_east,vector<double> vec_z_west,vector<int> vec_layer,vector<int> vec_wire,vector<double> vec_z,vector<double>& vec_zStereo,vector<double>& l,vector<bool> vec_truthHit){
1876 for(
int i=0;i<
n;i++){
1877 if(vec_truthHit[i]==
false)
continue;
1880 if(vec_slant[i]!=0){
1881 if(vec_x_east[i]!=vec_x_west[i]){
1882 k=(vec_y_east[i]-vec_y_west[i])/(vec_x_east[i]-vec_x_west[i]);
1883 b=-k*vec_x_east[i]+vec_y_east[i];
1885 double delta=4*(k*b-k*y_cirtemp-x_cirtemp)*(k*b-k*y_cirtemp-x_cirtemp)-4*(k*k+1)*(x_cirtemp*x_cirtemp+b*b+y_cirtemp*y_cirtemp-2*b*y_cirtemp-r_temp*r_temp);
1895 double x1=(2*x_cirtemp+2*k*y_cirtemp-2*k*b+sqrt(delta))/(2*(k*k+1));
1896 double x2=(2*x_cirtemp+2*k*y_cirtemp-2*k*b-sqrt(delta))/(2*(k*k+1));
1897 double x_middle=(vec_x_east[i]+vec_x_west[i])/2.;
1899 if(
abs(x1-x_middle)>
abs(x2-x_middle)) {x_stereo=x2;}
1901 y_stereo=k*x_stereo+b;
1906 x_stereo=vec_x_east[i];
1907 double y1=sqrt(r_temp*r_temp-(x_cirtemp-x_stereo)*(x_cirtemp-x_stereo))+y_cirtemp;
1908 double y2=y_cirtemp-sqrt(r_temp*r_temp-(x_cirtemp-x_stereo)*(x_cirtemp-x_stereo));
1909 double y_middle=(vec_y_east[i]+vec_y_west[i])/2.;
1910 if(
abs(y1-y_middle)>
abs(y2-y_middle)) {y_stereo=y2;}
1916 if(x_cirtemp==0||x_stereo-x_cirtemp==0){
1920 theta_temp=
M_PI-atan2(y_stereo-y_cirtemp,x_stereo-x_cirtemp)+atan2(y_cirtemp,x_cirtemp);
1921 if(theta_temp>2*
M_PI){
1922 theta_temp=theta_temp-2*
M_PI;
1925 theta_temp=theta_temp+2*
M_PI;
1936 l.push_back(r_temp*theta_temp);
1941 double d1=sqrt((x_stereo-vec_x_west[i])*(x_stereo-vec_x_west[i])+(y_stereo-vec_y_west[i])*(y_stereo-vec_y_west[i]));
1942 double d2=sqrt((vec_x_east[i]-vec_x_west[i])*(vec_x_east[i]-vec_x_west[i])+(vec_y_east[i]-vec_y_west[i])*(vec_y_east[i]-vec_y_west[i]));
1943 vec_zStereo.push_back(vec_z_west[i]-(vec_z_west[i]-vec_z_east[i])*d1/d2);
1962 stereoId=stereoId+1;
1967 cout<<
"nDropDelta: "<<nDropDelta<<endl;
1985void MdcHoughFinder::Linefit(
int z_stereoNum,vector<double> vec_zStereo,vector<double> l,
double& tanl,
double& z0){
1992 for(
int i=0;i<z_stereoNum;i++){
1995 z_sum=z_sum+vec_zStereo[i];
1996 l2_sum=l2_sum+l[i]*l[i];
1998 z2_sum=z2_sum+vec_zStereo[i]*vec_zStereo[i];
1999 lz_sum=lz_sum+l[i]*vec_zStereo[i];
2001 double b=(l2_sum*z_sum-lz_sum*l_sum)/(z_stereoNum*l2_sum-l_sum);
2002 double k=(z_stereoNum*lz_sum-l_sum*z_sum)/(z_stereoNum*l2_sum-l_sum*l_sum);
2005 cout<<k<<
" "<<b<<endl;
2010int MdcHoughFinder::digiToHots2(
TrkRecoTrk* newTrack,vector<bool> vec_truthHit){
2027 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
2029 for (;iter1 != mdcDigiVec.end(); iter1++, digiId++) {
2032 if(vec_truthHit[digiId]==
false)
continue;
2033 const MdcDigi* aDigi = *iter1;
2043 if(m_debug>0) std::cout<<
" ("<<layer<<
","<<wire<<
") "<<std::endl;
2056 double fltLen = m_gm->
Layer(layer)->
rMid();
2061 if(m_debug>2) std::cout<<
" ("<<layer<<
","<<wire<<
",rt "<<hit->
rawTime()<<
",dt "<<hit->
driftTime(m_bunchT0,0)<<
") T0 " << m_mdcCalibFunSvc->
getT0(layer,wire) <<
" timewalk "<< m_mdcCalibFunSvc->
getTimeWalk(layer, aDigi->
getChargeChannel())<<endl;
2063 if(hit->
driftDist(m_bunchT0,0)>1.2)
continue;
2067 if(m_debug>1) std::cout<<std::endl;
2068 return trkHitList->
nHit();
2070void MdcHoughFinder:: Multi_array(
int binX,
int binY){
2071 int **
count=
new int*[binX];
2072 for(
int i=0;i<binX;i++){
2073 count[i]=
new int [binY];
2076 int ***selectNum=
new int**[binX];
2077 for(
int i=0;i<binX;i++){
2078 selectNum[i]=
new int* [binY];
2079 for(
int j=0;j<binY;j++){
2081 selectNum[i][j]=
new int [
count[i][j]];
2085void MdcHoughFinder::FillCells(TH2D *h1,
int n,
int binX,
int binY,vector<double> vec_u,vector<double> vec_v,vector<int> vec_layer,vector<int> vec_wire,vector< vector <int> >& countij,vector< vector < vector<int> > >& vec_selectNum,vector< vector < vector<int> > >& vec_selectHit){
2086 double binWidth=
M_PI/binX;
2087 double binHigh=2*t_maxP/binY;
2098 for(
int i=0;i<binX;i++){
2099 for(
int j=0;j<binY;j++){
2101 double binLeft=i*binWidth;
2102 double binRight=(i+1)*binWidth;
2103 double binDown=-t_maxP+j*binHigh;
2104 double binUp=-t_maxP+(j+1)*binHigh;
2105 double binMid=(binLeft+binRight)/2;
2106 for(
int k=0;k<
n;k++){
2107 double lineLeft=vec_u[k]*
cos(binLeft)+vec_v.at(k)*
sin(binRight);
2108 double lineRight=vec_u[k]*
cos(binLeft)+vec_v.at(k)*
sin(binRight);
2109 double lineMid=vec_u[k]*
cos(binMid)+vec_v[k]*
sin(binMid);
2110 if(((lineLeft<binUp)&&(lineLeft>binDown)) || ((lineRight<binUp)&&(lineRight>binDown)) || (((lineLeft-binUp)*(binDown-lineRight)>0))){
2111 vec_selectNum[i][j].push_back(k);
2112 int layerId=vec_layer[k];
2113 int cellId=vec_wire[k];
2114 int hit_temp=(int)layerId*1000+cellId;
2115 vec_selectHit[i][j].push_back(hit_temp);
2119 countij[i][j]=
count;
2127 if(m_debug>0) cout<<
"countij: "<<countij[i][j]<<endl;
2138 for(
int i=0;i<binX;i++){
2139 for(
int j=0;j<binY;j++){
2140 h1->SetBinContent(i+1,j+1,countij[i][j]);
2144void MdcHoughFinder::RhoTheta(
int numCross,
int nhit,vector<double> vec_u,vector<double> vec_v,vector<double>& vec_rho,vector<double>& vec_theta,vector< vector<int> >& vec_hitNum){
2145 for(
int i=0;i<nhit;i++){
2146 for(
int j=i+1;j<nhit;j++){
2147 double k,b,x_cross,y_cross;
2148 double rho_temp,theta_temp;
2149 k=(vec_v[i]-vec_v[j])/(vec_u[i]-vec_u[j]);
2150 b=vec_v[i]-k*vec_u[i];
2153 rho_temp=sqrt(x_cross*x_cross+y_cross*y_cross);
2154 theta_temp=atan2(y_cross,x_cross);
2156 theta_temp=theta_temp+
M_PI;
2159 vec_rho.push_back(rho_temp);
2160 vec_theta.push_back(theta_temp);
2161 vec_hitNum[0].push_back(i);
2162 vec_hitNum[1].push_back(j);
2169 for(
int i=0;i<numCross;i++){
2170 m_rho[i]=vec_rho[i];
2171 m_theta[i]=vec_theta[i];
2175void MdcHoughFinder::FillHist(TH2D *h1,vector<double> vec_u,vector<double> vec_v,
int nhit,vector< vector < vector< int > > > vec_selectNum){
2176 for(
int n=0;
n<nhit;
n++){
2177 for(
int i=0;i<binX;i++){
2178 double binwidth=
M_PI/binX;
2179 double binhigh=2*t_maxP/binY;
2180 double binMid=(i+0.5)*binwidth;
2181 double rho=vec_u[
n]*
cos(binMid)+vec_v[
n]*
sin(binMid);
2182 int j=(int)((rho+t_maxP)/binhigh);
2184 count=h1->GetBinContent(i+1,j+1);
2186 h1->SetBinContent(i+1,j+1,count);
2204void MdcHoughFinder::FillRhoTheta(TH2D *h1 ,vector<double> vec_theta,vector<double> vec_rho,
int numCross){
2205 for(
int i=0;i<numCross;i++){
2206 double binwidth=
M_PI/binX;
2207 double binhigh=2*t_maxP/binY;
2208 int binxNum=vec_theta[i]/binwidth+1;
2209 int binyNum=(vec_rho[i]+t_maxP)/binhigh+1;
2210 int count =h1->GetBinContent(binxNum,binyNum);
2212 h1->SetBinContent(binxNum,binyNum,count);
std::vector< MdcDigi * > MdcDigiVec
HepGeom::Point3D< double > HepPoint3D
double sin(const BesAngle a)
double cos(const BesAngle a)
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
NTuple::Item< long > m_nHit
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
double bFieldNominal() const
double cosTheta(void) const
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
double dr(void) const
returns an element of parameters.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
double getT0(int layid, int cellid) const
double getTimeWalk(int layid, double Q) const
const MdcLayer * Layer(unsigned id) const
static MdcDetector * instance()
HepPoint3D Forward(void) const
HepPoint3D Backward(void) const
const MdcGeoWire *const Wire(unsigned id)
void setCalibSvc(const MdcCalibFunSvc *calibSvc)
double driftTime(double tof, double z) const
void setCountPropTime(const bool count)
double driftDist(double, int, double, double, double) const
MdcHoughFinder(const std::string &name, ISvcLocator *pSvcLocator)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
void storeTrack(int trackId, RecMdcTrackCol *trackList, RecMdcHitCol *hitList, int tkStat)
static void readMCppTable(std::string filenm)
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
virtual Identifier identify() const
unsigned int getChargeChannel() const
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
const TrkHotList & hotList() const
hot_iterator begin() const
virtual void print(std::ostream &) const
const TrkFit * fitResult() const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const
_EXTERN_ std::string RecMdcTrackCol
_EXTERN_ std::string RecMdcHitCol