1#include "MdcHoughFinder/HoughValidUpdate.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 "MdcRawEvent/MdcDigi.h"
13#include "Identifier/Identifier.h"
14#include "Identifier/MdcID.h"
17#include "EvTimeEvent/RecEsTime.h"
18#include "RawDataProviderSvc/MdcRawDataProvider.h"
19#include "McTruth/MdcMcHit.h"
20#include "MdcRecEvent/RecMdcTrack.h"
21#include "MdcRecEvent/RecMdcHit.h"
22#include "TrkBase/TrkFit.h"
23#include "TrkBase/TrkHitList.h"
24#include "TrkBase/TrkExchangePar.h"
25#include "TrkFitter/TrkHelixMaker.h"
26#include "TrkFitter/TrkCircleMaker.h"
27#include "TrkFitter/TrkLineMaker.h"
28#include "TrkFitter/TrkHelixFitter.h"
29#include "MdcxReco/Mdcxprobab.h"
30#include "MdcData/MdcHit.h"
31#include "MdcData/MdcRecoHitOnTrack.h"
32#include "MdcTrkRecon/MdcTrack.h"
33#include "MdcGeom/EntranceAngle.h"
34#include "TrackUtil/Helix.h"
35#include "GaudiKernel/IPartPropSvc.h"
36#include "MdcRecoUtil/Pdt.h"
37#include "RawEvent/RawDataUtil.h"
38#include "TrkBase/TrkErrCode.h"
39#include "MdcPrintSvc/MdcPrintSvc.h"
52 Algorithm(name, pSvcLocator)
55 declareProperty(
"drawTuple", m_drawTuple=0);
56 declareProperty(
"useMcInfo", m_useMcInfo=0);
57 declareProperty(
"method", m_method=0);
58 declareProperty(
"debug", m_debug = 0);
59 declareProperty(
"data", m_data= 0);
60 declareProperty(
"binx", m_binx= 100);
61 declareProperty(
"biny", m_biny= 200);
62 declareProperty(
"maxrho", m_maxrho= 0.3);
63 declareProperty(
"peakCellNumX", m_peakCellNumX);
64 declareProperty(
"peakCellNumY", m_peakCellNumY);
65 declareProperty(
"ndev1", m_ndev1= 1);
66 declareProperty(
"ndev2", m_ndev2= 5);
67 declareProperty(
"f_hit_pro", m_hit_pro= 0.4);
68 declareProperty(
"pdtFile", m_pdtFile =
"pdt.table");
69 declareProperty(
"pickHits", m_pickHits =
true);
70 declareProperty(
"pid", m_pid = 0);
71 declareProperty(
"combineTracking",m_combineTracking =
false);
72 declareProperty(
"getDigiFlag", m_getDigiFlag = 0);
73 declareProperty(
"maxMdcDigi", m_maxMdcDigi = 0);
74 declareProperty(
"keepBadTdc", m_keepBadTdc = 0);
75 declareProperty(
"dropHot", m_dropHot= 0);
76 declareProperty(
"keepUnmatch", m_keepUnmatch = 0);
77 declareProperty(
"minMdcDigi", m_minMdcDigi = 0);
78 declareProperty(
"setnpeak_fit", m_setpeak_fit= -1);
79 declareProperty(
"Q", m_q= 0);
80 declareProperty(
"eventcut", m_eventcut= -1);
81 declareProperty(
"rhocut", m_rhocut= -1.);
82 declareProperty(
"mcpar", m_mcpar= 0);
83 declareProperty(
"fillTruth", m_fillTruth= 0);
84 declareProperty(
"removeBadTrack", m_removeBadTrack=
false);
85 declareProperty(
"dropTrkDrCut", m_dropTrkDrCut= 1.);
86 declareProperty(
"dropTrkDzCut", m_dropTrkDzCut= 10.);
87 declareProperty(
"dropTrkPtCut", m_dropTrkPtCut= 99999.);
88 declareProperty(
"dropTrkChi2Cut", m_dropTrkChi2Cut = 99999.);
89 declareProperty(
"dropTrkChi2NdfCut", m_dropTrkChi2NdfCut = 99999.);
90 declareProperty(
"qualityFactor", m_qualityFactor= 3.);
91 declareProperty(
"dropTrkNhitCut", m_dropTrkNhitCut= 9);
98 if(NULL == m_gm)
return StatusCode::FAILURE;
100 return StatusCode::SUCCESS;
106 MsgStream log(
msgSvc(), name());
107 log << MSG::INFO <<
"in initialize()" << endreq;
112 IPartPropSvc* p_PartPropSvc;
113 static const bool CREATEIFNOTTHERE(
true);
114 sc = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
115 if (!sc.isSuccess() || 0 == p_PartPropSvc) {
116 log << MSG::ERROR <<
" Could not initialize PartPropSvc" << endreq;
119 m_particleTable = p_PartPropSvc->PDT();
123 sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
125 if ( sc.isFailure() ){
126 log << MSG::FATAL << name()<<
" Could not load RawDataProviderSvc!" << endreq;
127 return StatusCode::FAILURE;
133 sc = service (
"MdcGeomSvc", imdcGeomSvc);
134 m_mdcGeomSvc =
dynamic_cast<MdcGeomSvc*
> (imdcGeomSvc);
135 if ( sc.isFailure() ){
136 log << MSG::FATAL <<
"Could not load MdcGeoSvc!" << endreq;
137 return StatusCode::FAILURE;
142 sc = service (
"MdcPrintSvc", iMdcPrintSvc);
143 m_mdcPrintSvc=
dynamic_cast<MdcPrintSvc*
> (iMdcPrintSvc);
144 if ( sc.isFailure() ){
145 log << MSG::FATAL <<
"Could not load MdcPrintSvc!" << endreq;
146 return StatusCode::FAILURE;
149 sc = service (
"MagneticFieldSvc",m_pIMF);
150 if(sc!=StatusCode::SUCCESS) {
151 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
153 m_bfield =
new BField(m_pIMF);
154 log << MSG::INFO <<
"field z = "<<m_bfield->
bFieldNominal()<< endreq;
162 sc = service (
"MdcCalibFunSvc", imdcCalibSvc);
164 if ( sc.isFailure() ){
165 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endreq;
166 return StatusCode::FAILURE;
171 NTuplePtr nt1(
ntupleSvc(),
"HoughValidUpdate/hit");
175 ntuplehit =
ntupleSvc()->book(
"HoughValidUpdate/hit", CLID_ColumnWiseTuple,
"hit");
177 ntuplehit->addItem(
"eventNum", m_eventNum);
178 ntuplehit->addItem(
"runNum", m_runNum);
179 ntuplehit->addItem(
"nHitMc", m_nHit_Mc,0, 6796);
180 ntuplehit->addItem(
"nHitAxialMc", m_nHitAxial_Mc);
181 ntuplehit->addItem(
"layerMc", m_nHit_Mc, m_layer_Mc);
182 ntuplehit->addItem(
"cellMc", m_nHit_Mc, m_cell_Mc);
184 ntuplehit->addItem(
"nTrkMC", m_nTrkMC,0,10);
185 ntuplehit->addItem(
"pidTruth", m_nTrkMC,m_pidTruth);
186 ntuplehit->addItem(
"costaTruth", m_nTrkMC,m_costaTruth);
187 ntuplehit->addItem(
"ptTruth", m_nTrkMC,m_ptTruth);
188 ntuplehit->addItem(
"pzTruth", m_nTrkMC,m_pzTruth);
189 ntuplehit->addItem(
"pTruth", m_nTrkMC,m_pTruth);
190 ntuplehit->addItem(
"qTruth", m_nTrkMC,m_qTruth);
191 ntuplehit->addItem(
"drTruth", m_nTrkMC,m_drTruth);
192 ntuplehit->addItem(
"phiTruth", m_nTrkMC,m_phi0Truth);
193 ntuplehit->addItem(
"omegaTruth", m_nTrkMC,m_omegaTruth);
194 ntuplehit->addItem(
"dzTruth", m_nTrkMC,m_dzTruth);
195 ntuplehit->addItem(
"tanlTruth", m_nTrkMC,m_tanl_mc);
197 ntuplehit->addItem(
"nHit", m_nHit,0, 6796);
198 ntuplehit->addItem(
"nHitDigi", m_nHitDigi);
199 ntuplehit->addItem(
"nHitAxial", m_nHitAxial);
200 ntuplehit->addItem(
"nHitStereo", m_nHitStereo);
201 ntuplehit->addItem(
"layer", m_nHit, m_layer);
202 ntuplehit->addItem(
"cell", m_nHit, m_cell);
203 ntuplehit->addItem(
"x_east", m_nHit, m_x_east);
204 ntuplehit->addItem(
"y_east", m_nHit, m_y_east);
205 ntuplehit->addItem(
"z_east", m_nHit, m_z_east);
206 ntuplehit->addItem(
"x_west", m_nHit, m_x_west);
207 ntuplehit->addItem(
"y_west", m_nHit, m_y_west);
208 ntuplehit->addItem(
"z_west", m_nHit, m_z_west);
209 ntuplehit->addItem(
"x", m_nHit, m_x);
210 ntuplehit->addItem(
"y", m_nHit, m_y);
211 ntuplehit->addItem(
"z", m_nHit, m_z);
212 ntuplehit->addItem(
"u", m_nHit, m_u);
213 ntuplehit->addItem(
"v", m_nHit, m_v);
214 ntuplehit->addItem(
"p", m_nHit, m_p);
215 ntuplehit->addItem(
"slant", m_nHit, m_slant);
216 ntuplehit->addItem(
"layerNhit", 43, m_layerNhit);
217 ntuplehit->addItem(
"layerMax", m_layer_max);
218 ntuplehit->addItem(
"l_truth", m_nHit, m_ltruth);
219 ntuplehit->addItem(
"z_truth", m_nHit, m_ztruth);
220 ntuplehit->addItem(
"z_postruth", m_nHit, m_postruth);
221 ntuplehit->addItem(
"digi_truth", m_nHit, m_digi_truth);
222 ntuplehit->addItem(
"e_delta", m_e_delta);
224 ntuplehit->addItem(
"nCross", m_nCross, 0, 125000);
225 ntuplehit->addItem(
"rho", m_nCross, m_rho);
226 ntuplehit->addItem(
"theta", m_nCross, m_theta);
227 ntuplehit->addItem(
"xybinNum", m_xybinNum, 0,100000);
228 ntuplehit->addItem(
"xybin", m_xybinNum, m_xybin);
229 ntuplehit->addItem(
"xsigma", m_xsigma);
230 ntuplehit->addItem(
"ysigma", m_ysigma);
232 ntuplehit->addItem(
"npeak_1", m_npeak_1);
233 ntuplehit->addItem(
"npeak_2", m_npeak_2);
234 ntuplehit->addItem(
"trackFailure", m_trackFailure);
235 ntuplehit->addItem(
"npeak_after_tracking", m_npeak_after_tracking, 0,1000);
236 ntuplehit->addItem(
"nHitSelect", m_npeak_after_tracking, m_nHitSelect);
237 ntuplehit->addItem(
"nHitAxialSelect", m_npeak_after_tracking, m_nHitAxialSelect);
238 ntuplehit->addItem(
"nHitStereoSelect", m_npeak_after_tracking, m_nHitStereoSelect);
239 ntuplehit->addItem(
"naxiallose", m_npeak_after_tracking, m_axiallose);
240 ntuplehit->addItem(
"nstereolose", m_npeak_after_tracking, m_stereolose);
242 ntuplehit->addItem(
"trackNum_Mc", m_trackNum_Mc, 0,100);
243 ntuplehit->addItem(
"trackNum", m_trackNum, 0,100);
244 ntuplehit->addItem(
"trackNum_fit", m_trackNum_fit, 0,100);
245 ntuplehit->addItem(
"trackNum_tds", m_trackNum_tds, 0,100);
246 ntuplehit->addItem(
"circleCenterX", m_trackNum, m_x_circle);
247 ntuplehit->addItem(
"circleCenterY", m_trackNum, m_y_circle);
248 ntuplehit->addItem(
"circleR", m_trackNum, m_r);
249 ntuplehit->addItem(
"chis_pt", m_trackNum, m_chis_pt);
250 ntuplehit->addItem(
"pt_rec", m_trackNum, m_pt);
252 ntuplehit->addItem(
"nHitStereo_use",m_nHitStereo_use,0,1000);
253 ntuplehit->addItem(
"l_Calcu_Left", m_nHitStereo_use, m_lCalcuLeft);
254 ntuplehit->addItem(
"l_Calcu_Right", m_nHitStereo_use, m_lCalcuRight);
255 ntuplehit->addItem(
"z_Calcu_Left", m_nHitStereo_use, m_zCalcuLeft);
256 ntuplehit->addItem(
"z_Calcu_Right", m_nHitStereo_use, m_zCalcuRight);
257 ntuplehit->addItem(
"z_Calcu", m_nHitStereo_use, m_zCalcu);
258 ntuplehit->addItem(
"l_Calcu", m_nHitStereo_use, m_lCalcu);
259 ntuplehit->addItem(
"z_delta", m_nHitStereo_use, m_delta_z);
260 ntuplehit->addItem(
"l_delta", m_nHitStereo_use, m_delta_l);
261 ntuplehit->addItem(
"amb", m_nHitStereo_use, m_amb);
262 ntuplehit->addItem(
"amb_no_match", m_ambig_no_match);
263 ntuplehit->addItem(
"amb_no_match_pro", m_ambig_no_match_propotion);
264 ntuplehit->addItem(
"tanl_Cal", m_tanl_Cal);
265 ntuplehit->addItem(
"z0_Cal", m_z0_Cal);
267 ntuplehit->addItem(
"pt2_rec_final", m_trackNum_fit, m_pt2_rec_final);
268 ntuplehit->addItem(
"p_rec_final", m_trackNum_fit, m_p_rec_final);
269 ntuplehit->addItem(
"d0_final", m_trackNum_fit, m_d0_final);
270 ntuplehit->addItem(
"phi0_final", m_trackNum_fit, m_phi0_final);
271 ntuplehit->addItem(
"omega_final", m_trackNum_fit, m_omega_final);
272 ntuplehit->addItem(
"z0_final", m_trackNum_fit, m_z0_final);
273 ntuplehit->addItem(
"tanl_final", m_trackNum_fit, m_tanl_final);
274 ntuplehit->addItem(
"chis_3d_final", m_trackNum_fit, m_chis_3d_final);
275 ntuplehit->addItem(
"Q_final", m_trackNum_fit, m_Q);
277 ntuplehit->addItem(
"pt2_rec_tds", m_trackNum_tds, m_pt2_rec_tds);
278 ntuplehit->addItem(
"p_rec_tds", m_trackNum_tds, m_p_rec_tds);
279 ntuplehit->addItem(
"d0_tds", m_trackNum_tds, m_d0_tds);
280 ntuplehit->addItem(
"phi0_tds", m_trackNum_tds, m_phi0_tds);
281 ntuplehit->addItem(
"omega_tds", m_trackNum_tds, m_omega_tds);
282 ntuplehit->addItem(
"z0_tds", m_trackNum_tds, m_z0_tds);
283 ntuplehit->addItem(
"tanl_tds", m_trackNum_tds, m_tanl_tds);
284 ntuplehit->addItem(
"Q_tds", m_trackNum_tds, m_Q_tds);
287 ntuplehit->addItem(
"nhitdis0", m_nhitdis0, 0,2000);
288 ntuplehit->addItem(
"nhitdis1", m_nhitdis1, 0,2000);
289 ntuplehit->addItem(
"nhitdis2", m_nhitdis2, 0,2000);
290 ntuplehit->addItem(
"hitdis0", m_nhitdis0, m_hit_dis0);
291 ntuplehit->addItem(
"hitdis1", m_nhitdis1, m_hit_dis1);
292 ntuplehit->addItem(
"hitdis2", m_nhitdis2, m_hit_dis2);
293 ntuplehit->addItem(
"hitdis1_3d", m_nhitdis1, m_hit_dis1_3d);
294 ntuplehit->addItem(
"hitdis2_3d", m_nhitdis2, m_hit_dis2_3d);
295 ntuplehit->addItem(
"track_use_intrk1", m_track_use_intrk1);
296 ntuplehit->addItem(
"noise_intrk1", m_noise_intrk1);
297 ntuplehit->addItem(
"decay", m_decay);
298 ntuplehit->addItem(
"outputTrk", m_outputTrk, 0,100);
299 ntuplehit->addItem(
"hitOnTrk", m_outputTrk, m_hitOnTrk);
302 }
else { log << MSG::ERROR <<
"Cannot book tuple HoughValidUpdate/hough" << endmsg;
303 return StatusCode::FAILURE;
310 return StatusCode::SUCCESS;
320 MsgStream log(
msgSvc(), name());
321 log << MSG::INFO <<
"in execute()" << endreq;
324 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
326 log << MSG::WARNING<<
"Could not retrieve RecEsTimeCol , use t0=0" << endreq;
329 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
330 if (iter_evt != evTimeCol->end()){
331 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
336 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
338 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
339 return( StatusCode::FAILURE);
342 DataObject *aTrackCol;
343 DataObject *aRecHitCol;
344 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
345 if(!m_combineTracking){
346 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
347 if(aTrackCol != NULL) {
348 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
349 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
351 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
352 if(aRecHitCol != NULL) {
353 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
354 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
359 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
365 if(!sc.isSuccess()) {
366 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
367 return StatusCode::FAILURE;
372 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
378 if(!sc.isSuccess()) {
379 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
380 return StatusCode::FAILURE;
385 if(m_removeBadTrack) {
386 vector<RecMdcTrack*> vec_trackList;
387 if( m_debug>0 ) cout<<
"PATTSF collect "<<trackList->size()<<
" track. "<<endl;
388 if(trackList->size()!=0){
389 RecMdcTrackCol::iterator iter_pat = trackList->begin();
390 for(;iter_pat!=trackList->end();iter_pat++){
391 double d0=(*iter_pat)->helix(0);
392 double kap = (*iter_pat)->helix(2);
394 if(fabs(kap)>0.00001) pt = fabs(1./kap);
395 double dz=(*iter_pat)->helix(4);
396 double chi2=(*iter_pat)->chi2();
397 if( m_debug>0) cout<<
"d0: "<<d0<<
" z0: "<<dz<<
" pt "<<pt<<
" chi2 "<<chi2<<endl;
398 if(fabs(d0)>m_dropTrkDrCut || fabs(dz)>m_dropTrkDzCut || chi2>m_dropTrkChi2Cut || pt>m_dropTrkPtCut) {
399 vec_trackList.push_back(*iter_pat);
401 HitRefVec rechits = (*iter_pat)->getVecHits();
402 HitRefVec::iterator hotIter = rechits.begin();
403 while (hotIter!=rechits.end()) {
404 if(m_debug>0) cout <<
"remove hit " << (*hotIter)->getId() <<endl;
405 hitList->remove(*hotIter);
408 trackList->remove(*iter_pat);
414 if(m_debug>0) cout<<
" PATTSF find 0 track. "<<endl;
418 int nTdsTk=trackList->size();
421 t_eventNum=eventHeader->eventNumber();
422 t_runNum=eventHeader->runNumber();
424 m_eventNum=t_eventNum;
427 if(m_debug>0) cout<<
" begin event :"<<t_eventNum<<endl;
428 if(t_eventNum<=m_eventcut) {
429 cout<<
" eventNum cut "<<t_eventNum<<endl;
430 return StatusCode::SUCCESS;
432 log << MSG::INFO <<
"HoughValidUpdate: retrieved event: " << eventHeader->eventNumber() <<
" run: " << eventHeader->runNumber() << endreq;
434 vector<double> vec_u;
435 vector<double> vec_v;
436 vector<double> vec_p;
437 vector<double> vec_x_east;
438 vector<double> vec_y_east;
439 vector<double> vec_z_east;
440 vector<double> vec_x_west;
441 vector<double> vec_y_west;
442 vector<double> vec_z_west;
443 vector<double> vec_z_Mc;
444 vector<double> vec_x;
445 vector<double> vec_y;
446 vector<double> vec_z;
447 vector<int> vec_layer;
448 vector<int> vec_wire;
449 vector<int> vec_slant;
450 vector<double> vec_zStereo;
453 vector<int> vec_layer_Mc;
454 vector<int> vec_wire_Mc;
455 vector<int> vec_hit_Mc;
456 vector<double> vec_ztruth_Mc;
457 vector<double> vec_flt_truth_mc;
458 vector<double> vec_pos_flag;
459 vector<double> vec_phit_MC;
462 int mc_particle=GetMcInfo();
463 if(m_debug>2) cout<<
"MC particle : "<<mc_particle<<endl;
466 if(m_fillTruth ==1 && m_useMcInfo) {
469 SmartDataPtr<Event::MdcMcHitCol> mcMdcMcHitCol(eventSvc(),
"/Event/MC/MdcMcHitCol");
470 if (!mcMdcMcHitCol) {
471 log << MSG::INFO <<
"Could not find MdcMcHit" << endreq;
473 Event::MdcMcHitCol::iterator iterMcHit = mcMdcMcHitCol->begin();
475 for(; iterMcHit != mcMdcMcHitCol->end(); ++iterMcHit,digiId_Mc++) {
479 double hittemp=layerId_Mc*1000+wireId_Mc;
480 double mc_hit_distance =(*iterMcHit)->getDriftDistance();
481 double z_mc = (*iterMcHit)->getPositionZ()/10.;
482 double flt_truth=(z_mc-dz_mc)/tanl_mc;
483 double pos_flag=(*iterMcHit)->getPositionFlag();
486 if( (*iterMcHit)->getPositionFlag()==-999 ){
488 double px= (*iterMcHit)->getPositionX();
489 double py= (*iterMcHit)->getPositionY();
490 double pz= (*iterMcHit)->getPositionZ();
491 double pxyz = sqrt(px*px+py*py+pz*pz);
492 vec_phit_MC.push_back(pxyz);
502 vec_layer_Mc.push_back(layerId_Mc);
503 vec_wire_Mc.push_back(wireId_Mc);
504 vec_hit_Mc.push_back(hittemp);
505 vec_ztruth_Mc.push_back(z_mc);
506 vec_flt_truth_mc.push_back(flt_truth);
507 vec_pos_flag.push_back(pos_flag);
510 cout<<
"(" <<layerId_Mc<<
","<<wireId_Mc<<
"):"<<endl;
511 cout<<
" hit_distance : "<<mc_hit_distance<<endl;
512 cout<<
" position flag : "<<pos_flag<<endl;
513 cout<<
" hit_z_mc : "<<z_mc<<endl;
514 cout<<
" flt_truth : "<<flt_truth<<endl;
518 if ((layerId_Mc>=8&&layerId_Mc<=19)||(layerId_Mc>=36)) {
520 const MdcGeoWire *geowir =m_mdcGeomSvc->
Wire(layerId_Mc,wireId_Mc);
524 double x = (*iterMcHit)->getPositionX()/10.;
525 double y = (*iterMcHit)->getPositionY()/10.;
526 double z = (*iterMcHit)->getPositionZ()/10.;
527 double u=CFtrans(
x,y);
528 double v=CFtrans(y,
x);
529 double p=sqrt(u*u+
v*
v);
531 vec_x_east.push_back(eastP.x());
532 vec_y_east.push_back(eastP.y());
533 vec_z_east.push_back(eastP.z());
534 vec_x_west.push_back(westP.x());
535 vec_y_west.push_back(westP.y());
536 vec_z_west.push_back(westP.z());
543 vec_slant.push_back( SlantId(layerId_Mc) );
545 m_x_east[digiId_Mc]=eastP.x();
546 m_y_east[digiId_Mc]=eastP.y();
547 m_z_east[digiId_Mc]=eastP.z();
548 m_x_west[digiId_Mc]=westP.x();
549 m_y_west[digiId_Mc]=westP.y();
550 m_z_west[digiId_Mc]=westP.z();
551 m_layer[digiId_Mc]=layerId_Mc;
552 m_cell[digiId_Mc]=wireId_Mc;
559 m_slant[digiId_Mc]=SlantId(layerId_Mc);
564 m_nHitAxial_Mc=nHitAxial_Mc;
565 if(0==m_data) {m_nHit=digiId_Mc; m_nHitAxial=nHitAxial_Mc;}
570 vector<int> vec_track_index;
572 uint32_t getDigiFlag = 0;
578 if(m_debug>0) cout<<
"MdcDigiVec: "<<mdcDigiVec.size()<<endl;
579 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
582 for (;iter1 != mdcDigiVec.end(); iter1++, digiId++) {
586 double hittemp=layerId*1000+wireId;
590 if ((layerId>=8&&layerId<=19)||(layerId>=36)) nHitAxial++;
592 int track_index=(*iter1)->getTrackIndex();
593 if( track_index>=1000 ) track_index-=1000;
594 if( track_index<0 ) hit_noise.insert(hittemp);
595 int tchannal=(*iter1)->getTimeChannel();
596 int qchannal=(*iter1)->getChargeChannel();
597 if( tchannal!=qchannal && m_debug>0 ) cout<<
"("<<layerId<<
","<<wireId<<
")"<< 0<<endl;
598 if( m_debug>3 ) cout<<
"track_index in digi: "<<
"("<<layerId<<
","<<wireId<<
" "<< track_index<<endl;
599 if( m_debug>3 ) cout<<
"event: "<<t_eventNum<<
" "<<
"layer: "<<layerId<<
" "<<
"wireId: "<<wireId<<
" "<<
"zeast: "<<eastP.z()<<
" "<<
"zwest: "<<westP.z()<<
" "<<endl;
602 double x =(eastP.x()+westP.x())/2.;
603 double y =(eastP.y()+westP.y())/2.;
604 double u=CFtrans(
x,y);
605 double v=CFtrans(y,
x);
606 if(m_debug>3) cout<<
"digiId: "<<digiId<<
" layer: "<<layerId<<
" "<<
"wireId: "<<wireId<<
" "<<
"x: "<<
x<<
" "<<
"y: "<<y<<
" "<<
"u: "<<u<<
"v: "<<
v<<endl;
608 vec_track_index.push_back(track_index);
609 vec_layer.push_back(layerId);
610 vec_wire.push_back(wireId);
611 vec_hit.push_back(hittemp);
612 vec_x_east.push_back(eastP.x());
613 vec_y_east.push_back(eastP.y());
614 vec_z_east.push_back(eastP.z());
615 vec_x_west.push_back(westP.x());
616 vec_y_west.push_back(westP.y());
617 vec_z_west.push_back(westP.z());
620 vec_p.push_back(sqrt(u*u+
v*
v));
623 vec_slant.push_back( SlantId(layerId) );
626 m_x_east[digiId]=eastP.x();
627 m_y_east[digiId]=eastP.y();
628 m_z_east[digiId]=eastP.z();
629 m_x_west[digiId]=westP.x();
630 m_y_west[digiId]=westP.y();
631 m_z_west[digiId]=westP.z();
632 m_layer[digiId]=layerId;
633 m_cell[digiId]=wireId;
634 m_x[digiId]=(vec_x_east[digiId]+vec_x_west[digiId])/2;
635 m_y[digiId]=(vec_y_east[digiId]+vec_y_west[digiId])/2;
638 m_p[digiId]=sqrt(u*u+
v*
v);
639 m_slant[digiId]=SlantId( layerId );
640 m_layerNhit[layerId]++;
645 m_nHitAxial=nHitAxial;
646 m_nHitStereo=m_nHit-m_nHitAxial;
648 if(m_debug>0) cout<<
"Hit digi number: "<<digiId<<endl;
649 if(digiId<5||nHitAxial<3) {
650 if(m_drawTuple) m_trackFailure=1;
651 if(m_drawTuple) ntuplehit->write();
652 if(m_debug>0) cout<<
"not enough hit "<<endl;
653 return StatusCode::SUCCESS;
657 vector<int> vec_digitruth(digiId,0);
658 vector<double> vec_flt_truth(digiId,999.);
659 vector<double> vec_ztruth(digiId,999.);
660 vector<double> vec_posflag_truth(digiId,999.);
662 int if_exit_delta_e=0;
664 for(
int iHit=0;iHit<digiId;iHit++){
665 vector<int>::iterator iter_ihit = find( vec_hit_Mc.begin(),vec_hit_Mc.end(),vec_hit[iHit] );
666 if( iter_ihit==vec_hit_Mc.end() ) {
667 vec_digitruth[iHit]=0;
668 if(m_drawTuple) m_digi_truth[iHit]=0;
672 vec_digitruth[iHit]=1;
673 m_digi_truth[iHit]=1;
676 for(
int iHit_Mc=0;iHit_Mc<vec_flt_truth_mc.size();iHit_Mc++){
677 if(vec_hit[iHit]==vec_hit_Mc[iHit_Mc]) {
678 vec_flt_truth[iHit]=vec_flt_truth_mc[iHit_Mc];
679 vec_ztruth[iHit]=vec_ztruth_Mc[iHit_Mc];
680 vec_posflag_truth[iHit]=vec_pos_flag[iHit_Mc];
682 m_ztruth[iHit]=vec_ztruth_Mc[iHit_Mc];
683 m_ltruth[iHit]=vec_flt_truth_mc[iHit_Mc];
684 m_postruth[iHit]=vec_pos_flag[iHit_Mc];
688 if(m_debug>3) cout<<
" hitPos: "<<
"("<<vec_layer[iHit]<<
","<<vec_wire[iHit]<<
")"<<
" flt_truth: "<<vec_flt_truth[iHit]<<
" z_truth: "<<vec_ztruth[iHit]<<
" pos_flag: "<<vec_posflag_truth[iHit]<<
" digi_truth: "<<vec_digitruth[iHit]<<endl;
691 m_e_delta=if_exit_delta_e;
692 m_nHitDigi=nhit_digi;
697 vector<int>::iterator laymax=max_element( vec_layer.begin(),vec_layer.end() );
698 if(m_drawTuple) m_layer_max=*laymax;
703 if(m_data==0 && m_useMcInfo && m_fillTruth) {
705 nhitaxial=m_nHitAxial_Mc;
714 TH2D *h1 =
new TH2D(
"h1",
"h1",binX,0,
M_PI,binY,-m_maxrho,m_maxrho);
715 TH2D *h2 =
new TH2D(
"h2",
"h2",binX,0,
M_PI,binY,-m_maxrho,m_maxrho);
786 vector< vector< vector<int> > > vec_selectNum(binX,vector< vector<int> >(binY,vector<int>() ) );
791 FillHist(h1,vec_u,vec_v,nhit,vec_selectNum);
795 for(
int i=0;i<binX;i++){
796 for(
int j=0;j<binY;j++){
797 int count=h1->GetBinContent(i+1,j+1);
798 if(max_count<count) {
806 if(vec_selectNum[max_binx-1][max_biny-1].size() != max_count ) cout<<
"ERROR IN VEC!!! "<<endl;
808 cout<<
"maxBin: ["<<max_binx-1<<
","<<max_biny-1<<
"]: "<<vec_selectNum[max_binx-1][max_biny-1].size()<<endl;
809 for(
int i =0;i<vec_selectNum[max_binx-1][max_biny-1].size();i++) cout<<
" maxBin select hit: "<<vec_selectNum[max_binx-1][max_biny-1][i]<<endl;
813 for(
int ibinx=0;ibinx<binX;ibinx++){
814 for(
int ibiny=0;ibiny<binY;ibiny++){
815 int bincount=h1->GetBinContent(ibinx+1,ibiny+1);
816 if(vec_selectNum[ibinx][ibiny].size() != bincount ) cout<<
"ERROR IN VECTORSELECT filling "<<endl;
817 if(vec_selectNum[ibinx][ibiny].size() == 0 )
continue;
818 cout<<
"bin:"<<
"["<<ibinx<<
","<<ibiny<<
"]"<<
" select:"<<vec_selectNum[ibinx][ibiny].size()<<endl;
819 for(
int i=0;i<vec_selectNum[ibinx][ibiny].size();i++){
820 int ihit=vec_selectNum[ibinx][ibiny][i];
821 cout<<
" hit: "<<ihit<<
" ("<<vec_layer[ihit]<<
","<<vec_wire[ihit]<<
")"<<endl;
832 for(
int i=0;i<binX;i++){
833 for(
int j=0;j<binY;j++){
834 int count=h1->GetBinContent(i+1,j+1);
843 double aver=sum/count_use;
844 double dev=sqrt(sum2/count_use-aver*aver);
845 int min_counts=(int)(aver+f_n*dev);
846 if (min_counts<m_ndev2) min_counts=m_ndev2;
847 if(m_debug>2) cout<<
"aver: "<<aver<<
" "<<
"dev: "<<dev<<
" min: "<<min_counts<<endl;
849 vector< vector <int> > hough_trans_CS(binX,vector <int> (binY,0) );
850 vector< vector <int> > hough_trans_CS_peak(binX,vector <int> (binY,0) );
851 for(
int i=0;i<binX;i++){
852 for(
int j=0;j<binY;j++){
853 hough_trans_CS[i][j]=h1->GetBinContent(i+1,j+1);
858 for (
int r=0; r<binY; r++) {
859 double binHigh=2*m_maxrho/binY;
860 double rho_peak=r*binHigh-m_maxrho;
861 for (
int a=0; a<binX; a++) {
863 for (
int ar=a-1; ar<=a+1; ar++) {
864 for (
int rx=r-1; rx<=r+1; rx++) {
866 if (ar<0) { ax=ar+binX; }
867 else if (ar>=binX) { ax=ar-binX; }
869 if ( (ax!=a || rx!=r) && rx>=0 && rx<binY) {
870 if (hough_trans_CS[ax][rx]>max_around) { max_around=hough_trans_CS[ax][rx]; }
875 if (hough_trans_CS[a][r]<=min_counts||fabs(rho_peak)<m_rhocut) { hough_trans_CS_peak[a][r]=0; }
876 else if (hough_trans_CS[a][r]<max_around) { hough_trans_CS_peak[a][r]=0; }
877 else if (hough_trans_CS[a][r]==max_around) { hough_trans_CS_peak[a][r]=1; }
878 else if (hough_trans_CS[a][r]>max_around) { hough_trans_CS_peak[a][r]=2; }
879 if(hough_trans_CS_peak[a][r]!=0) {
880 if(m_debug>2) cout<<
" possible peak1:"<<
"["<<a<<
","<<r<<
"]"<<
": "<<hough_trans_CS_peak[a][r]<<
" "<<hough_trans_CS[a][r]<<endl;
889 for (
int r=0; r<binY; r++) {
890 for (
int a=0; a<binX; a++) {
891 if (hough_trans_CS_peak[a][r]==1) {
892 hough_trans_CS_peak[a][r]=2;
893 for (
int ar=a-1; ar<=a+1; ar++) {
894 for (
int rx=r-1; rx<=r+1; rx++) {
896 if (ar<0) { ax=ar+binX; }
897 else if (ar>=binX) { ax=ar-binX; }
899 if ( (ax!=a || rx!=r) && rx>=0 && rx<binY) {
900 if (hough_trans_CS_peak[ax][rx]==1) { hough_trans_CS_peak[ax][rx]=0; }
905 if(hough_trans_CS_peak[a][r]==2) {
906 double binHigh=2*m_maxrho/binY;
907 double rho_peak=r*binHigh-m_maxrho;
910 cout<<
" possible peak2: "<<
"["<<a<<
","<<r<<
"]"<<
": "<<hough_trans_CS_peak[a][r]<<
" "<<hough_trans_CS[a][r]<<
" rhopeak: "<<rho_peak<<endl;
911 for(
int i=0;i<hough_trans_CS[a][r];i++){
912 int hitNum=vec_selectNum[a][r][i];
913 if(m_debug>2) cout<<
" select hit: "<<hitNum<<
"("<<vec_layer[hitNum]<<
","<<vec_wire[hitNum]<<
")"<<endl;
921 for(
int i=0;i<binX;i++){
922 for(
int j=0;j<binY;j++){
923 if(hough_trans_CS_peak[i][j]==2){
924 h2->SetBinContent(i+1,j+1,hough_trans_CS[i][j]);
929 vector<int> peakList[3];
930 for(
int n=0;
n<npeak_2;
n++){
931 for (
int r=0; r<binY; r++) {
932 for (
int a=0; a<binX; a++) {
933 if (hough_trans_CS_peak[a][r]==2) {
934 peakList[0].push_back(a);
935 peakList[1].push_back(r);
936 peakList[2].push_back(hough_trans_CS[a][r]);
947 cout<<
"npeak_1: "<<npeak_1<<endl;
948 cout<<
"npeak_2: "<<npeak_2<<endl;
953 for (
int na=0; na<npeak_2-1; na++) {
955 for (
int nb=na+1; nb<npeak_2; nb++) {
956 if (peakList[2][n_max]<peakList[2][nb]) { n_max=nb; }
960 for (
int i=0; i<3; i++) {
961 swap[i]=peakList[i][na];
962 peakList[i][na]=peakList[i][n_max];
963 peakList[i][n_max]=swap[i];
968 if(npeak_2==0||npeak_2>100){
969 if(m_debug>0) cout<<
" FAILURE IN NPEAK2 !!!!!! "<<endl;
976 if(m_drawTuple) ntuplehit->write();
977 return StatusCode::SUCCESS;
981 for(
int n=0;
n<npeak_2;
n++){
982 int bintheta=peakList[0][
n];
983 int binrho=peakList[1][
n];
984 int count=peakList[2][
n];
985 cout<<
"possible peakList after SORT: "<<
n<<
": "<<
"["<<bintheta<<
","<<binrho<<
"]: "<<count<<endl;
986 for(
int i=0;i<count;i++){
987 int hitNum=vec_selectNum[bintheta][binrho][i];
988 if(m_debug>2) cout<<
" "<<
" select hit:"<<
":"<<hitNum<<
" ------ "<<
"("<<vec_layer[hitNum]<<
","<<vec_wire[hitNum]<<
")"<<endl;
995 Combine(h1,m_peakCellNumX,m_peakCellNumY,vec_selectNum,peak_hit_list,peak_hit_num,peak_track,peakList);
996 if(m_drawTuple) m_npeak_after_tracking=peak_track;
998 if(m_debug>0) cout<<
"event"<<t_eventNum<<
": "<<
"has found: "<<peak_track<<
" track."<<endl;
999 for(
int i=0;i<peak_track;i++){
1000 if(m_debug>0) cout<<
"peak["<<i<<
"] collect "<<peak_hit_num[i]<<
" hits "<<endl;
1001 int nhitaxialselect=0;
1002 for(
int j =0;j<peak_hit_num[i];j++){
1003 int hit_number=peak_hit_list[i][j];
1004 if(vec_slant[hit_number]==0) nhitaxialselect++ ;
1005 if(m_debug>0) cout<<
" "<<
" collect hits: ("<<vec_layer[hit_number]<<
","<<vec_wire[hit_number]<<
")"<<endl;
1008 m_nHitSelect[i]=peak_hit_num[i];
1009 m_nHitAxialSelect[i]=nhitaxialselect;
1010 m_nHitStereoSelect[i]=peak_hit_num[i]-nhitaxialselect;
1011 m_axiallose[i]=m_nHitAxial-m_nHitAxialSelect[i];
1012 m_stereolose[i]=m_nHit-m_nHitSelect[i]-m_axiallose[i];
1017 vector<int> vec_hitbeforefit;
1018 vector<bool> vec_truthHit(nhit,
false);
1019 int peak_fit=peak_track;
1020 if(m_setpeak_fit!=-1) {
1021 peak_fit=m_setpeak_fit;
1023 if(m_drawTuple) m_trackNum=peak_fit;
1025 vector<int> vec_hit_use;
1029 vector<TrkRecoTrk*> vec_newTrack;
1030 vector<TrkRecoTrk*> vec_track_in_tds;
1031 vector<int> vec_hitOnTrack;
1032 vector<MdcHit*> vec_for_clean;
1033 vector<TrkRecoTrk*> vec_trk_for_clean;
1034 vector<Mytrack> vec_myTrack;
1035 int track_fit_success=0;
1037 for(track_fit=0;track_fit<peak_fit;track_fit++){
1038 double d0_before_least=-999.;
1039 double phi0_before_least=-999.;
1040 double omega_before_least=-999.;
1041 map<int,double> hit_to_circle1;
1042 map<int,double> hit_to_circle2;
1043 map<int,double> hit_to_circle3;
1044 if(m_debug>0) cout<<
"Do fitting track: "<<track_fit<<endl;
1046 for(
int i=0;i<nhit;i++) vec_truthHit[i]=
false;
1049 if(m_debug>1) cout<<
"candi track["<<track_fit<<
"] collect "<<peak_hit_num[track_fit]<<
" hits "<<endl;
1051 for(
int i=0;i<peak_hit_num[track_fit];i++){
1052 int hitNum=peak_hit_list[track_fit][i];
1053 int hittemp=vec_layer[hitNum]*1000+vec_wire[hitNum];
1054 vector<int>::iterator iter_ihit = find( vec_hit_use.begin(),vec_hit_use.end(),hittemp );
1055 if( iter_ihit==vec_hit_use.end() ) vec_truthHit[hitNum]=
true;
1056 if( m_debug >1 && vec_truthHit[hitNum]==
true) cout<<
" "<<
"collect hit :"<<
"("<<vec_layer[hitNum]<<
","<<vec_wire[hitNum]<<
")"<<
" "<<endl;;
1059 for(
int i=0;i<nhit;i++){
1060 if(vec_truthHit[i]==
false){
1061 cout<<
"candi track "<<
"uncollect hit: "<<endl;
1062 cout<<
" "<<
"uncollect hit :"<<
"("<<vec_layer[i]<<
","<<vec_wire[i]<<
")"<<
" " <<endl;
1067 int t_nHitAxialSelect=0;
1068 for(
int i=0;i<nhit;i++){
1069 if(vec_truthHit[i]==
true){
1070 if(vec_slant[i]==0) t_nHitAxialSelect++;
1073 if(m_debug>1) cout<<
"track "<<track_fit<<
" with axial select: "<<t_nHitAxialSelect<<endl;
1074 if(t_nHitAxialSelect<3 && m_drawTuple){
1075 m_x_circle[track_fit]=-999.;
1076 m_y_circle[track_fit]=-999.;
1077 m_r[track_fit]=-999.;
1078 m_chis_pt[track_fit] = -999.;
1079 m_pt[track_fit]=-999.;
1085 int leastSquare=LeastSquare(nhit,vec_x,vec_y,vec_slant,vec_layer,vec_truthHit,d0_before_least,phi0_before_least,omega_before_least,circle_x,circle_y,circle_r);
1087 for(
int i=0;i<nhit;i++){
1088 int hittemp=vec_layer[i]*1000+vec_wire[i];
1089 double dist_temp=sqrt(pow( (vec_y[i]-circle_y),2)+pow( (vec_x[i]-circle_x),2))-circle_r;
1090 if(dist_temp>10.) vec_truthHit[i]=
false;
1091 if(m_debug>1&&vec_truthHit[i]==
true) cout<<
"IN LEAST1: "<<
"("<<vec_layer[i]<<
","<<vec_wire[i]<<
"):"<<dist_temp<<endl;
1094 t_nHitAxialSelect=0;
1095 for(
int i=0;i<nhit;i++){
1096 if(vec_truthHit[i]==
true){
1097 if(vec_slant[i]==0) t_nHitAxialSelect++;
1100 if(m_debug>1) cout<<
"track "<<track_fit<<
"with axial2 select: "<<t_nHitAxialSelect<<endl;
1101 if(t_nHitAxialSelect<3)
continue;
1103 int leastSquare2=LeastSquare(nhit,vec_x,vec_y,vec_slant,vec_layer,vec_truthHit,d0_before_least,phi0_before_least,omega_before_least,circle_x,circle_y,circle_r);
1104 for(
int i=0;i<nhit;i++){
1105 int hittemp=vec_layer[i]*1000+vec_wire[i];
1106 double dist_temp=sqrt(pow( (vec_y[i]-circle_y),2)+pow( (vec_x[i]-circle_x),2))-circle_r;
1107 hit_to_circle1[hittemp]=dist_temp;
1108 if(m_debug>1&&vec_truthHit[i]==
true) cout<<
" IN LEAST2: "<<
"("<<vec_layer[i]<<
","<<vec_wire[i]<<
"):"<<dist_temp<<endl;
1112 m_x_circle[track_fit]=circle_x;
1113 m_y_circle[track_fit]=circle_y;
1114 m_r[track_fit]=circle_r;
1115 m_chis_pt[track_fit]=circle_r/333.567;
1122 const TrkFit* newFit2[2];
1126 double Q_Chis_2d[]={9999,9999};
1127 double Q_Chis_3d[]={9999,9999};
1128 double Q_z[]={999,999};
1129 double Q_pt2[]={999,999};
1130 double Q_tanl[]={999,999};
1135 if(m_q==-1) {q_start=0;q_end=0;}
1136 if(m_q==1) {q_start=1;q_end=1;}
1137 for(
int i_q=q_start;i_q<=q_end;i_q++){
1138 double d0=d0_before_least;
1139 double phi0=phi0_before_least;
1140 double omega=omega_before_least;
1144 cout<<
"BY LEASTSQUARE: "<<endl;
1145 cout<<
" d0: "<<d0<<
" d0_mc "<<d0_mc<<endl;
1146 cout<<
" phi0: "<<phi0<<
" phi0_mc "<<phi0_mc<<endl;
1147 cout<<
" omega0: "<<omega<<
" omega_mc "<<omega_mc<<endl;
1150 vector<double> vec_flt_least;
1151 for(
int i=0;i<nhit;i++){
1153 if(circle_x==0||vec_x[i]-circle_x==0){
1157 theta_temp=
M_PI-atan2(vec_y[i]-circle_y,vec_x[i]-circle_x)+atan2(circle_y,circle_x);
1158 if(theta_temp>2*
M_PI){
1159 theta_temp=theta_temp-2*
M_PI;
1162 theta_temp=theta_temp+2*
M_PI;
1166 double l_temp=circle_r*theta_temp;
1167 vec_flt_least.push_back(l_temp);
1170 theta_temp=2*
M_PI-theta_temp;
1171 double l_temp=circle_r*(theta_temp);
1172 vec_flt_least.push_back(l_temp);
1176 for(
int i=0;i<nhit;i++){
1177 cout<<
"By least 2d: "<<
"("<<vec_layer[i]<<
","<<vec_wire[i]<<
"):"<<vec_flt_least[i]<<endl;
1201 bool permitFlips =
true;
1202 bool lPickHits = m_pickHits;
1204 int nDigi = digiToHots(mdcDigiVec,newTrack,vec_truthHit,getDigiFlag,vec_flt_least,hit_to_circle1,vec_for_clean);
1210 qhits[i_q] = newTrack->
hits();
1215 if (!newFit[i_q] || (newFit[i_q]->nActive()<3) || err.
failure()!=0) {
1217 cout <<
"evt "<<t_eventNum<<
" global 2d fit failed ";
1218 if(newFit[i_q]) cout <<
" nAct "<<newFit[i_q]->
nActive();
1219 cout<<
"ERR1 failure ="<<err.
failure()<<endl;
1224 Q_Chis_2d[i_q]=-999.;
1230 if(m_debug>0) cout <<
"evt "<<t_eventNum<<
" global 2d fit success"<<endl;
1232 newTrack->
print(std::cout);
1234 Q_Chis_2d[i_q]=newFit[i_q]->
chisq();
1240 r_temp=Q_iq[i_q]/par.
omega();
1244 if(m_debug>1) cout<<
" circle after globle 2d: "<<
"("<<x_cirtemp<<
","<<y_cirtemp<<
","<<r_temp<<
")"<<endl;
1245 if(m_debug>0) cout<<
"pt_rec: "<<-1*Q_iq[i_q]/omega/333.567<<endl;
1248 m_x_circle[track_fit]=x_cirtemp;
1249 m_y_circle[track_fit]=y_cirtemp;
1250 m_r[track_fit]=r_temp;
1251 m_chis_pt[track_fit] = newFit[i_q]->
chisq();
1252 m_pt[track_fit]=r_temp/333.567;
1257 if(m_debug>1) cout<<
" hot list:"<<endl;
1259 int lay=((
MdcHit*)(hotIter->hit()))->layernumber();
1260 int wir=((
MdcHit*)(hotIter->hit()))->wirenumber();
1261 int hittemp=lay*1000+wir;
1262 while (hotIter!=qhits[i_q]->hotList().
end()) {
1263 if(m_debug>1){ cout <<
"(" <<((
MdcHit*)(hotIter->hit()))->layernumber()
1264 <<
","<<((
MdcHit*)(hotIter->hit()))->wirenumber()
1265 <<
":"<<hotIter->isActive()<<
") ";
1267 if (hotIter->isActive()==1) nfit2d++;
1270 if(m_debug>0) cout<<
"charge "<<i_q<<
" In 2Dfit Num Of Active Hits: "<<nfit2d<<endl;
1273 if(m_debug>0 && m_drawTuple){
1274 cout<<
" By global 2d charge "<<i_q<<endl;
1275 cout<<
" d0: " <<d0<<
" "<<m_drTruth[0]<<endl;
1276 cout<<
" phi0: " <<phi0<<
" "<<m_phi0Truth[0]<<endl;
1277 cout<<
" omega: "<<omega<<
" "<<m_omegaTruth[0]<<endl;
1278 cout<<
" z0: " <<z0<<
" "<<m_dzTruth[0]<<endl;
1279 cout<<
" tanl: "<<tanl<<
" "<<m_tanl_mc[0]<<endl;
1283 cout<<
"least:( "<<circle_x<<
","<<circle_y<<
","<<circle_r<<endl;
1284 cout<<
"2d:( "<<x_cirtemp<<
","<<y_cirtemp<<
","<<r_temp<<endl;
1289 vector<double> vec_flt;
1290 vector<double> vec_theta_ontrack;
1291 for(
int i=0;i<nhit;i++){
1293 if(x_cirtemp==0||vec_x[i]-x_cirtemp==0){
1297 theta_temp=
M_PI-atan2(vec_y[i]-y_cirtemp,vec_x[i]-x_cirtemp)+atan2(y_cirtemp,x_cirtemp);
1298 if(theta_temp>2*
M_PI){
1299 theta_temp=theta_temp-2*
M_PI;
1302 theta_temp=theta_temp+2*
M_PI;
1305 double l_temp=r_temp*theta_temp;
1306 vec_flt.push_back(l_temp);
1307 vec_theta_ontrack.push_back(theta_temp);
1311 theta_temp=2*
M_PI-theta_temp;
1312 double l_temp=r_temp*(theta_temp);
1313 vec_flt.push_back(l_temp);
1314 vec_theta_ontrack.push_back(theta_temp);
1321 for(
int i=0;i<nhit;i++){
1322 cout<<
"i: "<<
"theta: "<<vec_theta_ontrack[i]<<
" l: "<<vec_flt[i]<<endl;
1326 for(
int i=0;i<nhit;i++){
1327 int hittemp=vec_layer[i]*1000+vec_wire[i];
1328 double dist_temp=sqrt(pow( (vec_y[i]-y_cirtemp),2)+pow( (vec_x[i]-x_cirtemp),2))-r_temp;
1329 hit_to_circle2[hittemp]=dist_temp;
1332 vector<double> vec_l_Calcu_Left;
1333 vector<double> vec_l_Calcu_Right;
1334 vector<double> vec_z_Calcu_Left;
1335 vector<double> vec_z_Calcu_Right;
1336 vector<double> vec_z_Calcu;
1337 vector<double> vec_l_Calcu;
1338 vector<double> vec_delta_z;
1339 vector<double> vec_delta_l;
1341 double l_Calcu_Left=-999.;
1342 double l_Calcu_Right=-999.;
1343 double z_Calcu_Left=-999.;
1344 double z_Calcu_Right=-999.;
1345 double z_Calcu=-999.;
1346 double l_Calcu=-999.;
1347 double delta_z=-999.;
1348 double delta_l=-999.;
1350 MdcDigiVec::iterator iter2 = mdcDigiVec.begin();
1353 for (;iter2 != mdcDigiVec.end(); iter2++, digiId++) {
1354 if(vec_truthHit[digiId]==
false)
continue;
1355 if(vec_slant[digiId]==0)
continue;
1356 if(vec_theta_ontrack[digiId]>
M_PI)
continue;
1357 const MdcDigi* aDigi = *iter2;
1361 zPos=zPosition(*hit,m_bunchT0,x_cirtemp,y_cirtemp,r_temp,digiId,delta_z,delta_l,l_Calcu_Left,l_Calcu_Right,z_Calcu_Left,z_Calcu_Right,z_Calcu,l_Calcu,Q_iq[i_q]);
1362 if(m_debug>2) cout<<
"in ZS calcu hitPos: "<<
"("<<vec_layer[digiId]<<
","<<vec_wire[digiId]<<
")"<<
" l_truth: "<<vec_flt_truth[digiId]<<
" z_truth: "<<vec_ztruth[digiId]<<
" l_Cal: "<<l_Calcu<<
" z_Cal: "<<z_Calcu<<endl;
1364 if(zPos==-1||zPos==-2)
continue;
1365 vec_l_Calcu_Left.push_back(l_Calcu_Left);
1366 vec_l_Calcu_Right.push_back(l_Calcu_Right);
1367 vec_z_Calcu_Left.push_back(z_Calcu_Left);
1368 vec_z_Calcu_Right.push_back(z_Calcu_Right);
1369 vec_z_Calcu.push_back(z_Calcu);
1370 vec_l_Calcu.push_back(l_Calcu_Right);
1371 vec_delta_z.push_back(delta_z);
1372 vec_delta_l.push_back(delta_l);
1374 int nHitUseInZs=vec_delta_z.size();
1377 for(
int i=0;i<nHitUseInZs;i++){
1378 m_nHitStereo_use=vec_delta_z.size();
1379 m_lCalcuLeft[i]=vec_l_Calcu_Left[i];
1380 m_lCalcuRight[i]=vec_l_Calcu_Right[i];
1381 m_zCalcuLeft[i]=vec_z_Calcu_Left[i];
1382 m_zCalcuRight[i]=vec_z_Calcu_Right[i];
1383 m_lCalcu[i]=vec_l_Calcu[i];
1384 m_zCalcu[i]=vec_z_Calcu[i];
1385 m_delta_z[i]=vec_delta_z[i];
1386 m_delta_l[i]=vec_delta_l[i];
1391 vector< vector< vector <double> > > point(2, vector< vector<double> >(2,vector<double>() ));
1392 for(
int iHit=0;iHit<nHitUseInZs;iHit++){
1393 point[0][0].push_back(vec_l_Calcu_Left[iHit]);
1394 point[0][1].push_back(vec_z_Calcu_Left[iHit]);
1395 point[1][0].push_back(vec_l_Calcu_Right[iHit]);
1396 point[1][1].push_back(vec_z_Calcu_Right[iHit]);
1398 vector<int> ambigList;
1400 AmbigChoose(point,nHitUseInZs,ambigList,tanl,z0);
1406 if(m_useMcInfo && m_drawTuple){
1407 int ambig_no_match_num=0;
1408 for(
int iHit=0;iHit<nHitUseInZs;iHit++){
1409 if(ambigList[iHit]==0) ambigList[iHit]=1;
1410 else ambigList[iHit]=0;
1411 if(ambigList[iHit]!=m_postruth[iHit]) { m_ambig_no_match=1; ambig_no_match_num++; }
1413 m_ambig_no_match_propotion=(double)(ambig_no_match_num)/m_nHitStereo_use;
1414 for (
int iHit=0;iHit<ambigList.size();iHit++){
1415 m_amb[iHit]=ambigList[iHit];
1420 if(m_debug>0 && m_drawTuple){
1421 cout<<
"By 3d track zs fit:"<<endl;
1422 cout<<
"d0: "<<d0<<
" mc : "<<m_drTruth[0]<<endl;
1423 cout<<
"phi0: "<<phi0<<
" mc : "<<m_phi0Truth[0]<<endl;
1424 cout<<
"omega: "<<omega<<
" mc : "<<m_omegaTruth[0]<<endl;
1425 cout<<
"z0: "<<z0<<
" mc : "<<m_dzTruth[0]<<endl;
1426 cout<<
"tanl: "<<tanl<<
" mc : "<<m_tanl_mc[0]<<endl;
1431 phi0=m_phi0Truth[0];
1432 if(Q_iq[i_q]==-1) {phi0=m_phi0Truth[0]-3./2.*
M_PI;omega=m_omegaTruth[0];}
1433 else {phi0=m_phi0Truth[0]-1./2.*
M_PI;omega=-1*m_omegaTruth[0];}
1440 if(m_debug>0) cout<<
"become 3d fit "<<endl;
1444 newTrack2[i_q] = helixfactory.
makeTrack(tt2, chisum, *m_context, m_bunchT0);
1445 vec_trk_for_clean.push_back(newTrack2[i_q]);
1447 lPickHits = m_pickHits;
1448 helixfactory.
setFlipAndDrop(*newTrack2[i_q], permitFlips, lPickHits);
1449 int nDigi2 = digiToHots2(mdcDigiVec,newTrack2[i_q],vec_truthHit,vec_flt_truth,getDigiFlag,vec_slant,vec_l_Calcu,vec_flt,vec_theta_ontrack,vec_hitbeforefit,hit_to_circle2,vec_for_clean,tanl);
1451 cout<<__FILE__<<__LINE__<<
"AFTER digiToHots 3d ---------BEFORE 3d fit"<<endl;
1452 newTrack2[i_q]->
printAll(std::cout);
1455 qhits2[i_q] = newTrack2[i_q]->
hits();
1457 newFit2[i_q] = newTrack2[i_q]->
fitResult();
1458 int nActiveHit = newTrack2[i_q]->
hots()->
nActive();
1459 int fitSuccess_3d = 0;
1460 if (!newFit2[i_q] || (newFit2[i_q]->nActive()<5) || err2.
failure()!=0) {
1463 Q_Chis_3d[i_q]=-999.;
1465 cout <<
"evt "<<t_eventNum<<
" global 3d fit failed ";
1466 if(!newFit2[i_q]) cout<<
" newfit2 point is NULL!!!" <<endl;
1467 if(newFit2[i_q]) cout <<
" nAct "<<newFit2[i_q]->
nActive();
1468 cout<<
"ERR2 failure ="<<err2.
failure()<<endl;
1473 if(
abs( 1/(par2.
omega()) )>0.001){
1475 Q_Chis_3d[i_q]=newFit2[i_q]->
chisq();
1477 if(m_debug>0) cout <<
"evt "<<t_eventNum<<
" global 3d fit success "<<err2.
failure()<<endl;
1479 cout<<__FILE__<<__LINE__<<
"AFTER fit 3d "<<endl;
1480 newTrack2[i_q]->
print(std::cout);
1485 Q_Chis_3d[i_q]=-999.;
1486 if(m_debug>2) cout<<
"3dfit failure of omega "<<endl;
1488 bool badQuality =
false;
1491 if(fabs(Q_Chis_3d[i_q])>m_qualityFactor*m_dropTrkChi2Cut ){
1493 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by chi2 "<<Q_Chis_3d[i_q]<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkChi2Cut <<std::endl;
1497 if( fabs(par2.
d0())>m_qualityFactor*m_dropTrkDrCut) {
1499 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by d0 "<<par2.
d0()<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkDrCut <<std::endl;
1503 if( fabs(par2.
z0())>m_qualityFactor*m_dropTrkDzCut) {
1505 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by z0 "<<par2.
z0()<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkDzCut <<std::endl;
1509 if( (fabs(Q_Chis_3d[i_q])/qhits2[i_q]->nHit()) > m_qualityFactor*m_dropTrkChi2NdfCut) {
1511 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by chi2/ndf"<<(fabs(Q_Chis_3d[i_q])/qhits2[i_q]->
nHit()) <<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkChi2NdfCut<<std::endl;
1515 if( nActiveHit <= m_dropTrkNhitCut) {
1517 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by nhit"<<nActiveHit <<
" <= "<<m_qualityFactor<<
" * "<<m_dropTrkNhitCut<<std::endl;
1524 Q_Chis_3d[i_q]=-999.;
1525 if(m_debug>2) cout<<
"3dfit failure of bad quality"<<endl;
1531 if(fitSuccess_3d==1){
1534 cout<<
"BY 3d global fit charge "<<i_q<<endl;
1535 cout<<
"d0: "<<par2.
d0()<<endl;
1536 cout<<
"phi0: "<<par2.
phi0()<<endl;
1537 cout<<
"w: "<<par2.
omega()<<endl;
1538 cout<<
"z: "<<par2.
z0()<<endl;
1539 cout<<
"tanl: "<<par2.
tanDip()<<endl;
1541 r_temp=Q_iq[i_q]/par2.
omega();
1543 y_cirtemp = -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1544 if(m_debug>0) cout<<
" circle after globle 3d: "<<
"("<<x_cirtemp<<
","<<y_cirtemp<<
","<<r_temp<<
")"<<endl;
1545 double pxy=-1*r_temp/333.567;
1546 double pz=pxy*par2.
tanDip();
1547 double pxyz=sqrt(pxy*pxy+pz*pz);
1549 Q_pt2[i_q]=fabs(pxy);
1551 Q_tanl[i_q]=par2.
tanDip();
1557 for(
int i=0;i<nhit;i++){
1558 int hittemp=vec_layer[i]*1000+vec_wire[i];
1559 double dist_temp=sqrt(pow( (vec_y[i]-y_cirtemp),2)+pow( (vec_x[i]-x_cirtemp),2))-r_temp;
1560 hit_to_circle3[hittemp]=dist_temp;
1565 cout<<
"chis 2d: "<<Q_Chis_2d[0]<<
" "<<Q_Chis_2d[1]<<endl;
1566 cout<<
"chis 3d: "<<Q_Chis_3d[0]<<
" "<<Q_Chis_3d[1]<<endl;
1567 cout<<
"Z: "<<Q_z[0]<<
" "<<Q_z[1]<<endl;
1568 cout<<
"chis ok-: "<<Q_ok[0][0]<<
" "<<Q_ok[0][1]<<endl;
1569 cout<<
"chis ok+: "<<Q_ok[1][0]<<
" "<<Q_ok[1][1]<<endl;
1574 if(Q_ok[0][1]==1) Q_judge[0]=1;
1575 if(Q_ok[1][1]==1) Q_judge[1]=1;
1576 if(Q_judge[0]==1&&Q_judge[1]==0) Q=-1;
1577 if(Q_judge[0]==0&&Q_judge[1]==1) Q=1;
1578 if(Q_judge[0]==1&&Q_judge[1]==1) {
1579 if(fabs(Q_z[0])>fabs(Q_z[1])) Q=1;
1582 if(Q_judge[0]==0&&Q_judge[1]==0) {Q=0;
continue;}
1584 if(Q==-1) q_choose=0;
1585 if(Q== 1) q_choose=1;
1588 cout<<
"after q choose By 3d global fit: "<<Q<<endl;
1589 cout<<
"d0: "<<par_final.
d0()<<endl;
1590 cout<<
"phi0: "<<par_final.
phi0()<<endl;
1591 cout<<
"w: "<<par_final.
omega()<<endl;
1592 cout<<
"z: "<<par_final.
z0()<<endl;
1593 cout<<
"tanl: "<<par_final.
tanDip()<<endl;
1595 double pxy=-1*Q_iq[q_choose]/par_final.
omega()/333.567;
1596 double pz=pxy*par_final.
tanDip();
1597 double pxyz=sqrt(pxy*pxy+pz*pz);
1599 if(m_debug>0) cout<<
"pt2_rec: "<<pxy<<endl;
1601 m_pt2_rec_final[track_fit_success]=pxy;
1602 m_p_rec_final[track_fit_success]=pxyz;
1603 m_d0_final[track_fit_success]=par_final.
d0();
1604 m_phi0_final[track_fit_success]=par_final.
phi0();
1605 m_omega_final[track_fit_success]=par_final.
omega();
1606 m_z0_final[track_fit_success]=par_final.
z0();
1607 m_tanl_final[track_fit_success]=par_final.
tanDip();
1608 m_Q[track_fit_success]=Q;
1612 if(m_debug>1) cout<<
" hot list:"<<endl;
1614 while (hotIter2!=qhits2[q_choose]->hotList().end()) {
1615 int lay=((
MdcHit*)(hotIter2->hit()))->layernumber();
1616 int wir=((
MdcHit*)(hotIter2->hit()))->wirenumber();
1617 int hittemp=lay*1000+wir;
1618 if(m_debug>1){ cout <<
"(" <<((
MdcHit*)(hotIter2->hit()))->layernumber()
1619 <<
","<<((
MdcHit*)(hotIter2->hit()))->wirenumber()
1620 <<
":"<<hotIter2->isActive()<<
") ";
1622 if( hotIter2->isActive()==1) {
1624 if(track_fit_success==0) vec_hitOnTrack.push_back(hittemp);
1628 if(m_debug>0) cout<<
"In 3D fit Num Of Active Hits: "<<nfit3d<<endl;
1630 track_fit_success++;
1631 int choise_temp,choise_no;
1632 if(Q==-1) choise_temp=0,choise_no=1;
1633 if(Q==1) choise_temp=1,choise_no=0;
1634 vec_newTrack.push_back( newTrack2[choise_temp] );
1637 for(
int iTrack=0;iTrack<vec_newTrack.size();iTrack++){
1638 const TrkFit* newFit_combine = vec_newTrack[iTrack]->fitResult();
1640 double cx_combine=(-333.567/par_combine.
omega()+par_combine.
d0())*
cos(par_combine.
phi0());
1641 double cy_combine=(-333.567/par_combine.
omega()+par_combine.
d0())*
sin(par_combine.
phi0());
1642 double phi_combine=par_combine.
phi0()-
M_PI/2;
1643 double pxy_combine=1./par_combine.
omega()/333.567;
1644 if(pxy_combine<0) phi_combine+=
M_PI;
1645 if(phi_combine<0) phi_combine+=2*
M_PI;
1646 if(phi_combine>2*
M_PI) phi_combine-=2*
M_PI;
1649 mytrack.
pt=pxy_combine;
1650 mytrack.
charge=(int)(fabs(pxy_combine)/pxy_combine);
1651 mytrack.
phi=phi_combine;
1652 mytrack.
r=-333.567/par_combine.
omega();
1653 mytrack.
x_cir=cx_combine;
1654 mytrack.
y_cir=cy_combine;
1655 mytrack.
newTrack=vec_newTrack[iTrack];
1659 vec_myTrack.push_back(mytrack);
1663 std::sort(vec_myTrack.begin(),vec_myTrack.end(),
compare);
1665 for(
int i=0;i<vec_newTrack.size();i++){
1666 Mytrack *mytrack_i=&(vec_myTrack[i]);
1668 for(
int j=i+1;j<vec_newTrack.size();j++){
1669 Mytrack *mytrack_j=&(vec_myTrack[j]);
1672 if(fabs(mytrack_j->
r)*(1.-0.25) <= fabs(mytrack_i->
r) && fabs(mytrack_i->
r) <= fabs(mytrack_j->
r)*(1.+0.25)){
1673 if(fabs(mytrack_j->
x_cir-mytrack_i->
x_cir) <= fabs(mytrack_j->
r)*(0.25)&& fabs(mytrack_j->
y_cir-mytrack_i->
y_cir) <= fabs(mytrack_j->
r)*(0.25) ){
1682 vector<Mytrack> vec_mytrack_in_tds;
1683 for(
int i=0;i<track_fit_success;i++){
1684 Mytrack mytrack=vec_myTrack[i];
1686 vec_mytrack_in_tds.push_back(mytrack);
1691 m_trackNum_tds=nTrack_tds;
1692 m_trackNum_fit=track_fit_success;
1710 for(
int i=0;i<nTrack_tds;i++){
1711 Mytrack mytrack=vec_mytrack_in_tds[i];
1717 double cr= 1./ par_tds.
omega();
1718 double cx=
sin(par_tds.
phi0()) *(par_tds.
d0()+1/par_tds.
omega()) * -1.;
1719 double cy= -1.*
cos(par_tds.
phi0()) *(par_tds.
d0()+1/par_tds.
omega()) * -1;
1721 unsigned bestIndex = 0;
1722 double bestDiff = 1.0e+20;
1724 vector<double> a0,a1,a2,a3,a4;
1725 vector<double> zdelta;
1726 RecMdcTrackCol::iterator iteritrk = trackList->begin();
1728 for(;iteritrk!=trackList->end();iteritrk++){
1729 double pt=(*iteritrk)->pxy();
1730 a0.push_back( (*iteritrk)->helix(0) );
1731 a1.push_back( (*iteritrk)->helix(1) );
1732 a2.push_back( (*iteritrk)->helix(2) );
1733 a3.push_back( (*iteritrk)->helix(3) );
1734 a4.push_back( (*iteritrk)->helix(4) );
1735 zdelta.push_back( par_tds.
z0()-(*iteritrk)->helix(3) );
1739 cR=(-333.567)/a2[itrk];
1740 cX=(cR+a0[itrk])*
cos(a1[itrk]);
1741 cY=(cR+a0[itrk])*
sin(a1[itrk]);
1743 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1744 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1745 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1746 if(diff < bestDiff){
1755 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no merge "<<endl; }
1772 vec_track_in_tds.push_back(mytrack.
newTrack);
1774 int tkId = nTdsTk + itrack;
1775 mdcTrack->
storeTrack(tkId, trackList, hitList, tkStat);
1780 double pxy=1/par_tds.
omega()/333.567;
1781 double pz=pxy*par_tds.
tanDip();
1782 double pxyz=sqrt(pxy*pxy+pz*pz);
1784 m_pt2_rec_tds[itrack]=pxy;
1785 m_p_rec_tds[itrack]=pxyz;
1786 m_d0_tds[itrack]=par_tds.
d0();
1787 m_phi0_tds[itrack]=par_tds.
phi0();
1788 m_omega_tds[itrack]=par_tds.
omega();
1789 m_z0_tds[itrack]=par_tds.
z0();
1790 m_tanl_tds[itrack]=par_tds.
tanDip();
1791 m_Q_tds[itrack]=pxy>0?1:-1;
1795 if(m_drawTuple) m_outputTrk=outputTrk;
1796 int nTdsTk_temp=trackList->size();
1823 for(
int i=0;i<vec_for_clean.size();i++){
1824 delete vec_for_clean[i];
1826 for(
int i=0;i<vec_trk_for_clean.size();i++){
1829 vector<TrkRecoTrk*>::iterator iterTrk =find(vec_track_in_tds.begin(),vec_track_in_tds.end(),vec_trk_for_clean[i]);
1830 if(iterTrk ==vec_track_in_tds.end() )
delete vec_trk_for_clean[i];
1836 if(m_drawTuple) ntuplehit->write();
1837 if(m_debug>0) cout<<
"end event" <<endl;
1838 return StatusCode::SUCCESS;
1843 MsgStream log(
msgSvc(), name());
1846 log << MSG::INFO <<
"in finalize()" << endreq;
1847 return StatusCode::SUCCESS;
1849int HoughValidUpdate::digiToHots(
MdcDigiVec mdcDigiVec,
TrkRecoTrk* newTrack,vector<bool> vec_truthHit,uint32_t getDigiFlag,vector<double> vec_flt_least,map<int,double> hit_to_circle1,vector<MdcHit*>& vec_for_clean){
1852 if(m_debug>0) cout<<
"MdcDigiVec(in 2d fit): "<<mdcDigiVec.size()<<endl;
1853 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
1854 for (;
iter != mdcDigiVec.end();
iter++, digiId++) {
1855 if(vec_truthHit[digiId]==
false)
continue;
1858 vec_for_clean.push_back(hit);
1863 int hittemp=layer*1000+wire;
1864 if ((layer>=0&&layer<=7)||(layer>=20&&layer<=35)) {
continue;}
1872 double fltLen = m_gm->
Layer(layer)->
rMid();
1874 newhot->
setFltLen(vec_flt_least[digiId]);
1881 if(layer<8) ddCut=1.0;
1884 if(hit->
driftDist(m_bunchT0,0)>ddCut||vec_truthHit[digiId]==
false||fabs(hit_to_circle1[hittemp])>10.) { use_in2d=0; }
1885 if(m_debug>1) 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())<<
" m_bunchT0 "<<m_bunchT0<<
" hit to circle: "<<hit_to_circle1[hittemp]<<
" dist: "<<hit->
driftDist(m_bunchT0,0)<<
" use?: "<<use_in2d<<endl;
1887 if(use_in2d==0)
continue;
1891 if(m_debug>0) std::cout<<std::endl;
1892 return trkHitList->
nHit();
1895double HoughValidUpdate::CFtrans(
double x,
double y){
1896 return 2*
x/(
x*
x+y*y);
1899int HoughValidUpdate::SlantId(
int layer){
1900 if ((layer>=0&&layer<=7)||(layer>=20&&layer<=35)) {
1901 if ((layer>=0&&layer<=3)||(layer>=20&&layer<=23)||(layer>=28&&layer<=31)){
1912int HoughValidUpdate::GetMcInfo(){
1913 MsgStream log(
msgSvc(), name());
1915 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
1916 if (!mcParticleCol) {
1917 log << MSG::ERROR <<
"Could not find McParticle" << endreq;
1923 int t_pidTruth = -999;
1924 int t_McTkId = -999;
1926 vector<int> vec_decay;
1927 McParticleCol::iterator iter_mc = mcParticleCol->begin();
1928 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
1930 t_pidTruth = (*iter_mc)->particleProperty();
1931 bool t_decay= (*iter_mc)->decayInFlight();
1932 if(m_debug>0) cout<<
"Decay : "<<t_decay<<endl;
1933 vec_decay.push_back(t_decay);
1935 if(m_debug>2) cout<<
"tk "<<itk<<
" pid="<< t_pidTruth<< endl;
1936 if((m_pid!=0) && (t_pidTruth != m_pid)){
continue; }
1939 int pid = t_pidTruth;
1941 log << MSG::WARNING <<
"Wrong particle id" <<endreq;
1943 IPartPropSvc* p_PartPropSvc;
1944 static const bool CREATEIFNOTTHERE(
true);
1945 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
1946 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
1947 std::cout<<
" Could not initialize Particle Properties Service" << std::endl;
1949 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
1951 if( p_particleTable->particle(pid) ){
1952 name = p_particleTable->particle(pid)->name();
1953 t_qTruth = p_particleTable->particle(pid)->charge();
1954 }
else if( p_particleTable->particle(-pid) ){
1955 name =
"anti " + p_particleTable->particle(-pid)->name();
1956 t_qTruth = (-1)*p_particleTable->particle(-pid)->charge();
1958 if(m_debug>2) std::cout <<
" particle "<<name<<
" charge= "<<t_qTruth<<std::endl;
1961 t_McTkId = (*iter_mc)->trackIndex();
1962 double px = (*iter_mc)->initialFourMomentum().px();
1963 double py = (*iter_mc)->initialFourMomentum().py();
1964 double pz = (*iter_mc)->initialFourMomentum().pz();
1967 mchelix =
new Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);
1972 std::cout<<
"Truth tk "<<itk<<
" pid "<<pid<<
" charge "<<t_qTruth
1973 <<
" helix "<< mchelix->
a()<<
" p "<<mchelix->
momentum(0.)<<std::endl;
1977 m_pidTruth[itk] = t_pidTruth;
1978 m_costaTruth[itk] = mchelix->
cosTheta();
1979 m_ptTruth[itk] = mchelix->
pt();
1980 m_pTruth[itk] = mchelix->
momentum(0.).mag();
1981 m_qTruth[itk] = t_qTruth;
1982 m_drTruth[itk] = mchelix->
dr();
1983 m_phi0Truth[itk] = mchelix->
phi0();
1984 m_omegaTruth[itk] =1./(mchelix->
radius());
1985 m_dzTruth[itk] = mchelix->
dz();
1986 m_tanl_mc[itk] =mchelix->
tanl();
1990 cout<<
" d0: " <<
" "<<mchelix->
dr()<<endl;
1991 cout<<
" phi0: " <<
" "<<mchelix->
phi0()<<endl;
1992 cout<<
" omega: "<<
" "<<1./(mchelix->
radius())<<endl;
1993 cout<<
" z0: " <<
" "<<mchelix->
dz()<<endl;
1994 cout<<
" tanl: "<<
" "<<mchelix->
tanl()<<endl;
1995 cout<<
" pt: " <<
" "<<mchelix->
pt()<<endl;
1996 cout<<
" costaTruth: " <<
" "<<mchelix->
cosTheta()<<endl;
2001 vector<int>::iterator iter_idecay=find(vec_decay.begin(),vec_decay.end(),1 );
2002 if (iter_idecay==vec_decay.end() ) m_decay=0;
2007 if(m_debug>2) std::cout<<
"WARNING run "<<t_runNum<<
" evt "<<t_eventNum<<
" not single event. nTrkMc="<<itk<<std::endl;
2010 if(m_debug>2) std::cout<<
"nTrkMc=1"<<std::endl;
2017int HoughValidUpdate::LeastSquare(
int n,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,
double& circleX,
double& circleY,
double& circleR){
2034 double x_aver,y_aver,r2;
2036 for(
int i=0;i<
n;i++){
2037 if(vec_truthHit[i]==
false)
continue;
2038 if(vec_slant[i]!=0)
continue;
2039 x_sum=x_sum+vec_x[i];
2040 y_sum=y_sum+vec_y[i];
2041 x2_sum=x2_sum+vec_x[i]*vec_x[i];
2042 y2_sum=y2_sum+vec_y[i]*vec_y[i];
2043 x3_sum=x3_sum+vec_x[i]*vec_x[i]*vec_x[i];
2044 y3_sum=y3_sum+vec_y[i]*vec_y[i]*vec_y[i];
2045 x2y_sum=x2y_sum+vec_x[i]*vec_x[i]*vec_y[i];
2046 xy2_sum=xy2_sum+vec_x[i]*vec_y[i]*vec_y[i];
2047 xy_sum=xy_sum+vec_x[i]*vec_y[i];
2050 a1=x2_sum-x_sum*x_sum/
n;
2051 a2=xy_sum-x_sum*y_sum/
n;
2053 b2=y2_sum-y_sum*y_sum/
n;
2054 c1=(x3_sum+xy2_sum-x_sum*(x2_sum+y2_sum)/
n)/2.;
2055 c2=(y3_sum+x2y_sum-y_sum*(x2_sum+y2_sum)/
n)/2.;
2060 double x_cirtemp =(b1*c2-b2*c1)/(b1*b1-a1*b2);
2061 double y_cirtemp =(b1*c1-a1*c2)/(b1*b1-a1*b2);
2062 r2=(x2_sum+y2_sum-2*x_cirtemp*x_sum-2*y_cirtemp*y_sum)/
n+x_cirtemp*x_cirtemp+y_cirtemp*y_cirtemp;
2063 double r_temp=sqrt(r2);
2065 circleX = x_cirtemp;
2066 circleY = y_cirtemp;
2069 double d0_temp=sqrt(x_cirtemp*x_cirtemp+y_cirtemp*y_cirtemp)-r_temp;
2070 double pt_temp=r_temp/333.567;
2072 cout<<
" in least fit : "<<endl;
2073 cout<<
"rtemp: "<<r_temp<<
" "<<endl;
2074 cout<<
"xtemp: "<<x_cirtemp<<
" "<<endl;
2075 cout<<
"ytemp: "<<y_cirtemp<<
" "<<endl;
2076 cout<<
"d0temp: "<<d0_temp<<
" "<<endl;
2077 cout<<
"pt_temp: "<<pt_temp<<endl;
2082 phi0=atan2(y_cirtemp,x_cirtemp)+
M_PI/2.;
2086 if(m_debug>0) std::cout<<
" before global fit Helix PatPar :"<<d0<<
","<<phi0<<
","<<omega<<
","<<z0<<
","<<tanl<< std::endl;
2091int HoughValidUpdate::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){
2099 for(
int i=0;i<
n;i++){
2100 if(vec_truthHit[i]==
false)
continue;
2103 if(vec_slant[i]!=0){
2104 if(vec_x_east[i]!=vec_x_west[i]){
2105 k=(vec_y_east[i]-vec_y_west[i])/(vec_x_east[i]-vec_x_west[i]);
2106 b=-k*vec_x_east[i]+vec_y_east[i];
2108 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);
2118 double x1=(2*x_cirtemp+2*k*y_cirtemp-2*k*b+sqrt(delta))/(2*(k*k+1));
2119 double x2=(2*x_cirtemp+2*k*y_cirtemp-2*k*b-sqrt(delta))/(2*(k*k+1));
2120 double x_middle=(vec_x_east[i]+vec_x_west[i])/2.;
2122 if(
abs(x1-x_middle)>
abs(x2-x_middle)) {x_stereo=x2;}
2124 y_stereo=k*x_stereo+b;
2129 x_stereo=vec_x_east[i];
2130 double y1=sqrt(r_temp*r_temp-(x_cirtemp-x_stereo)*(x_cirtemp-x_stereo))+y_cirtemp;
2131 double y2=y_cirtemp-sqrt(r_temp*r_temp-(x_cirtemp-x_stereo)*(x_cirtemp-x_stereo));
2132 double y_middle=(vec_y_east[i]+vec_y_west[i])/2.;
2133 if(
abs(y1-y_middle)>
abs(y2-y_middle)) {y_stereo=y2;}
2139 if(x_cirtemp==0||x_stereo-x_cirtemp==0){
2143 theta_temp=
M_PI-atan2(y_stereo-y_cirtemp,x_stereo-x_cirtemp)+atan2(y_cirtemp,x_cirtemp);
2144 if(theta_temp>2*
M_PI){
2145 theta_temp=theta_temp-2*
M_PI;
2148 theta_temp=theta_temp+2*
M_PI;
2159 l.push_back(r_temp*theta_temp);
2164 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]));
2165 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]));
2166 vec_zStereo.push_back(vec_z_west[i]-(vec_z_west[i]-vec_z_east[i])*d1/d2);
2185 stereoId=stereoId+1;
2190 cout<<
"nDropDelta: "<<nDropDelta<<endl;
2208void HoughValidUpdate::Linefit(
int z_stereoNum,vector<double> vec_zStereo,vector<double> l,
double& tanl,
double& z0){
2215 for(
int i=0;i<z_stereoNum;i++){
2218 z_sum=z_sum+vec_zStereo[i];
2219 l2_sum=l2_sum+l[i]*l[i];
2221 z2_sum=z2_sum+vec_zStereo[i]*vec_zStereo[i];
2222 lz_sum=lz_sum+l[i]*vec_zStereo[i];
2224 double b=(l2_sum*z_sum-lz_sum*l_sum)/(z_stereoNum*l2_sum-l_sum);
2225 double k=(z_stereoNum*lz_sum-l_sum*z_sum)/(z_stereoNum*l2_sum-l_sum*l_sum);
2228 cout<<k<<
" "<<b<<endl;
2233int HoughValidUpdate::digiToHots2(
MdcDigiVec mdcDigiVec,
TrkRecoTrk* newTrack,vector<bool> vec_truthHit,vector<double> vec_flt_truth,uint32_t getDigiFlag, vector<int> vec_slant, vector<double> vec_l_Calcu,vector<double> vec_flt,vector<double> vec_theta_ontrack,vector<int>& vec_hitbeforefit,map<int,double> hit_to_circle2,vector<MdcHit*>& vec_for_clean,
double tanl){
2236 if(m_debug>0) cout<<
"MdcDigiVec(in 3d fit): "<<mdcDigiVec.size()<<endl;
2237 MdcDigiVec::iterator iter1 = mdcDigiVec.
begin();
2239 int nhit_beforefit_temp=0;
2240 for (;iter1 != mdcDigiVec.end(); iter1++, digiId++) {
2242 if(vec_theta_ontrack[digiId]>
M_PI)
continue;
2244 const MdcDigi* aDigi = *iter1;
2246 vec_for_clean.push_back(hit);
2251 int hittemp=layer*1000+wire;
2260 double fltLen = m_gm->
Layer(layer)->
rMid();
2273 if(layer<8) {ddCut=1.0; distcirCut=5;}
2274 else {ddCut=1.0; distcirCut=2;}
2276 if(hit->
driftDist(m_bunchT0,0)>ddCut||vec_truthHit[digiId]==
false||fabs(hit_to_circle2[hittemp])>distcirCut) { use_in3d=0; }
2277 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())<<
" vec_truth: "<<vec_truthHit[digiId]<<
" theta: "<<vec_theta_ontrack[digiId]<<
" ddcut?: "<<hit->
driftDist(m_bunchT0,0)<<
" distocir: "<<hit_to_circle2[hittemp]<<
" use:? "<<use_in3d<<endl;
2278 if(use_in3d==0)
continue;
2280 vec_hitbeforefit.push_back(hittemp);
2283 if(m_debug>0) std::cout<<std::endl;
2284 return trkHitList->
nHit();
2286void HoughValidUpdate:: Multi_array(
int binX,
int binY){
2287 int **
count=
new int*[binX];
2288 for(
int i=0;i<binX;i++){
2289 count[i]=
new int [binY];
2292 int ***selectNum=
new int**[binX];
2293 for(
int i=0;i<binX;i++){
2294 selectNum[i]=
new int* [binY];
2295 for(
int j=0;j<binY;j++){
2297 selectNum[i][j]=
new int [
count[i][j]];
2302void HoughValidUpdate::RhoTheta(
int nhit,vector<double> vec_u,vector<double> vec_v,vector<double>& vec_rho,vector<double>& vec_theta,vector< vector<int> >& vec_hitNum,vector<int> vec_digitruth){
2303 for(
int i=0;i<nhit;i++){
2304 if(vec_digitruth[i]==0)
continue;
2305 for(
int j=i+1;j<nhit;j++){
2306 if(vec_digitruth[j]==0)
continue;
2307 double k,b,x_cross,y_cross;
2308 double rho_temp,theta_temp;
2309 k=(vec_v[i]-vec_v[j])/(vec_u[i]-vec_u[j]);
2310 b=vec_v[i]-k*vec_u[i];
2313 rho_temp=sqrt(x_cross*x_cross+y_cross*y_cross);
2314 theta_temp=atan2(y_cross,x_cross);
2316 theta_temp=theta_temp+
M_PI;
2319 vec_rho.push_back(rho_temp);
2320 vec_theta.push_back(theta_temp);
2321 vec_hitNum[0].push_back(i);
2322 vec_hitNum[1].push_back(j);
2326 int nCross=vec_rho.size();
2327 m_nCross=vec_rho.size();
2328 if(m_nCross>125000) return ;
2331 for(
int i=0;i<nCross;i++){
2332 m_rho[i]=vec_rho[i];
2333 m_theta[i]=vec_theta[i];
2337void HoughValidUpdate::RhoThetaAxial(vector<int> vec_slant,
int nhit,vector<double> vec_u,vector<double> vec_v,vector<double>& vec_rho,vector<double>& vec_theta,vector< vector<int> >& vec_hitNum,vector<int> vec_digitruth){
2338 for(
int i=0;i<nhit;i++){
2339 if(vec_digitruth[i]==0)
continue;
2340 if(vec_slant[i]!=0)
continue;
2341 for(
int j=i+1;j<nhit;j++){
2342 if(vec_slant[j]!=0)
continue;
2343 if(vec_digitruth[j]==0)
continue;
2344 double k,b,x_cross,y_cross;
2345 double rho_temp,theta_temp;
2346 k=(vec_v[i]-vec_v[j])/(vec_u[i]-vec_u[j]);
2347 b=vec_v[i]-k*vec_u[i];
2350 rho_temp=sqrt(x_cross*x_cross+y_cross*y_cross);
2351 theta_temp=atan2(y_cross,x_cross);
2353 theta_temp=theta_temp+
M_PI;
2356 vec_rho.push_back(rho_temp);
2357 vec_theta.push_back(theta_temp);
2358 vec_hitNum[0].push_back(i);
2359 vec_hitNum[1].push_back(j);
2363 int nCross=vec_rho.size();
2364 if( m_drawTuple ) m_nCross=vec_rho.size();
2367 for(
int i=0;i<nCross;i++){
2368 m_rho[i]=vec_rho[i];
2369 m_theta[i]=vec_theta[i];
2374void HoughValidUpdate::FillHist(TH2D *h1,vector<double> vec_u,vector<double> vec_v,
int nhit,vector< vector < vector< int > > > &vec_selectNum){
2375 for(
int n=0;
n<nhit;
n++){
2377 for(
int i=0;i<binX;i++){
2378 double binwidth=
M_PI/binX;
2379 double binhigh=2*m_maxrho/binY;
2380 double theta=(i+0.5)*binwidth;
2381 double rho=vec_u[
n]*
cos(theta)+vec_v[
n]*
sin(theta);
2382 int j=(int)((rho+m_maxrho)/binhigh);
2383 int count=h1->GetBinContent(i+1,j+1);
2385 h1->SetBinContent(i+1,j+1,count);
2387 vec_selectNum[i][j].push_back(
n);
2391void HoughValidUpdate::FillRhoTheta(TH2D *h1 ,vector<double> vec_theta,vector<double> vec_rho){
2392 for(
int i=0;i<vec_theta.size();i++){
2393 double binwidth=
M_PI/binX;
2394 double binhigh=2*m_maxrho/binY;
2395 int binxNum=vec_theta[i]/binwidth+1;
2396 int binyNum=(vec_rho[i]+m_maxrho)/binhigh+1;
2397 int count =h1->GetBinContent(binxNum,binyNum);
2399 h1->SetBinContent(binxNum,binyNum,count);
2404int HoughValidUpdate::zPosition(
MdcHit& h,
double t0,
double x_cirtemp,
double y_cirtemp,
double r_temp,
int digiId,
double& delta_z,
double& delta_l,
double& l_Calcu_Left,
double& l_Calcu_Right,
double& z_Calcu_Left,
double& z_Calcu_Right,
double& z_Calcu,
double& l_Calcu,
int& i_q) {
2415 for(
int ambig=-1;ambig<=1;ambig=ambig+2){
2424 std::cout<<
"---------- "<<std::endl;
2427 std::cout<<
"fp rp "<<fp<<
" "<<rp<<std::endl;
2428 std::cout<<
"Xmid "<<X<<std::endl;
2449 HepPoint3D center (x_cirtemp, y_cirtemp, 0. );
2453 double wwmag2 = ww.mag2();
2454 double wwmag = sqrt(wwmag2);
2458 double driftdist = fabs( h.
driftDist(t0,ambig) );
2460 driftdist/wwmag * ww.y(), 0.);
2462 std::cout<<
"xc "<<x_cirtemp <<
" yc "<<y_cirtemp<<
" drfitdist "<<driftdist<<std::endl;
2465 std::cout<<
"lr "<<lr<<
" "<<
" ambig "<<ambig
2467 <<
" right "<<h.
driftDist(0,-1)<<std::endl;
2475 if (ambig == 0) lr =
ORIGIN;
2496 double vmag2 =
v.mag2();
2500 double wv = w.dot(
v);
2502 double d2 = wv * wv - vmag2 * (w.mag2() - r_temp * r_temp);
2504 std::cout<<
"X_fix "<<X<<
" center "<<center<<std::endl;
2505 std::cout<<
"V "<<V<<std::endl;
2506 std::cout<<
"w "<<w<<
" v "<<
v<<std::endl;
2507 std::cout<<
"wv "<<wv<<endl;
2508 cout<<
"d2: "<<d2<<endl;
2515 cout<<
"d2: "<<d2<<endl;
2516 std::cout <<
"in MdcSegInfoSterO !!! stereo: 0. > d2 = " << d2 <<
" "
2517 << ambig << std::endl;
2520 if (ambig==-1) return_d[ambig+1]=0;
2521 else return_d[ambig]=0;
2524 double d = sqrt(d2);
2529 l[0] =-1*( (- wv + d) / vmag2 );
2530 l[1] =-1*( (- wv - d) / vmag2 );
2534 z[0] = X.z() - l[0] * V.z();
2535 z[1] = X.z() - l[1] * V.z();
2555 std::cout <<
"X.z "<<X.z()<<
" V.z "<<V.z()<<std::endl;
2556 std::cout <<
"l0, l1 = " << l[0] <<
", " << l[1] << std::endl;
2557 std::cout <<
"rpz " << rp.z() <<
" fpz " << fp.z() << std::endl;
2558 std::cout <<
"z0 " << z[0] <<
" z1 " << z[1] << std::endl;
2562 if(m_debug>4)std::cout<<
" ambig = 0 " <<std::endl;
2563 if (z[0] > rp.z()+20. || z[0] < fp.z()-20.) {
2566 if (z[1] > rp.z()+20. || z[1] < fp.z()-20.) {
2570 if(m_debug>4)std::cout<<
" ambig != 0 " <<std::endl;
2572 if (fabs(z[0]/rp.z())>1.05 ) { ok[0] =
false; }
2574 if (fabs(z[1]/rp.z())>1.05 ) { ok[1] =
false; }
2576 if ((! ok[0]) && (! ok[1])) {
2577 if(m_debug>4&&(ambig!=0)&&fabs(z[1]/rp.z())>1.05)std::cout<<
" z[1] bad " << std::endl;
2578 if(m_debug>4&&(ambig!=0)&&fabs(z[0]/rp.z())>1.05)std::cout<<
" z[0] bad " << std::endl;
2581 std::cout<<
" z[1] bad " <<
"rpz " << rp.z() <<
" fpz " << fp.z()
2582 <<
"z0 " << z[0] <<
" z1 " << z[1] << std::endl;
2583 std::cout<<
" !ok[0] && !ok[1] return -2" <<std::endl;
2586 if (ambig==-1) return_ok[ambig+1]=0;
2587 else return_ok[ambig]=0;
2590 if (( ok[0]) && ( ok[1])) {
2594 if (ok[1]) best = 1;
2596 p[0] =
x + l[0] *
v;
2597 p[1] =
x + l[1] *
v;
2598 double cosdPhi = - center.dot((p[best] - center).unit()) / center.mag();
2600 if(fabs(cosdPhi)<=1.0) {
2601 dPhi = acos(cosdPhi);
2602 }
else if (cosdPhi>1.0) {
2607 double stemp=r_temp*dPhi;
2608 if( m_debug >1) cout<<
" ambig : "<<ambig<<
" z: "<<z[best]<<
" stemp: "<<stemp<<endl;
2609 double delta_temp=0;
2610 if(m_drawTuple && m_useMcInfo) delta_temp =z[best]-m_ztruth[digiId];
2611 if( m_debug >3) cout<<
"deltatemp: "<<delta_temp<<endl;
2619 z_Calcu_Left=z[best];
2622 if( m_debug >1 && m_drawTuple &&m_useMcInfo) cout<<
"ambig: "<<ambig<<
" zbest : "<<z[best]<<
" ztruth: "<<m_ztruth[digiId]<<endl;
2623 if( m_debug >1 && m_drawTuple &&m_useMcInfo) cout<<
"ambig: "<<ambig<<
" lbest : "<<stemp<<
" ltruth: "<<m_ltruth[digiId]<<endl;
2624 if( m_useMcInfo && m_drawTuple && m_postruth[digiId]==1) { z_Calcu=z[best]; l_Calcu=stemp; delta_z= delta_temp; delta_l =l_Calcu-m_ltruth[digiId];}
2627 z_Calcu_Right=z[best];
2628 l_Calcu_Right=stemp;
2630 if( m_debug >1 && m_drawTuple &&m_useMcInfo) cout<<
"ambig: "<<ambig<<
" zbest : "<<z[best]<<
" ztruth: "<<m_ztruth[digiId]<<endl;
2631 if( m_debug >1 && m_drawTuple &&m_useMcInfo) cout<<
"ambig: "<<ambig<<
" lbest : "<<stemp<<
" ltruth: "<<m_ltruth[digiId]<<endl;
2632 if( m_useMcInfo && m_drawTuple && m_postruth[digiId]==0) { z_Calcu=z[best]; l_Calcu=stemp; delta_z= delta_temp; delta_l =l_Calcu-m_ltruth[digiId];}
2685 if(return_d[0]==0&&return_d[1]==0)
return -1;
2686 if(return_ok[0]==0&&return_ok[1]==0)
return -2;
2689void HoughValidUpdate::AmbigChoose(vector< vector< vector<double> > > point,
int n_use,vector<int>& ambigList,
double& tanl,
double& z0){
2697 int ambig_combine=0;
2705 vector< vector <int> > select(4,vector<int>() );
2706 for(
int icombine1=0;icombine1<2;icombine1++){
2707 for(
int icombine2=0;icombine2<2;icombine2++){
2708 int combine=icombine1*2+icombine2;
2709 first_x[1]=point[icombine1][0][
n-1];
2710 first_x[2]=point[icombine2][0][
n-2];
2711 first_y[1]=point[icombine1][1][
n-1];
2712 first_y[2]=point[icombine2][1][
n-2];
2715 LeastLine(3,first_x,first_y,k,b,chi2);
2729 for(
int iHit=0;iHit<
n-2;iHit++){
2730 double dist_to_line[2];
2731 for(
int j=0;j<2;j++){
2732 double x=point[j][0][iHit];
2733 double y=point[j][1][iHit];
2734 dist_to_line[j]=(
abs(k*x-y+b) ) / sqrt( k*k +1);
2736 if(dist_to_line[0]>dist_to_line[1]) select[
combine].push_back(1);
2737 else select[
combine].push_back(0);
2740 select[
combine].push_back(icombine2);
2741 select[
combine].push_back(icombine1);
2747 double *l_new=
new double[
n+1];
2748 double *z_new=
new double[
n+1];
2749 for(
int i=0;i<
n;i++){
2751 l_new[i]=point[ambig][0][i];
2752 z_new[i]=point[ambig][1][i];
2766 double k_least,b_least;
2767 double chi2_least=0;
2768 LeastLine(
n+1,l_new,z_new,k_least,b_least,chi2_least);
2798 for(
int i=0;i<4;i++){
2799 if(Chis_Least>=Chis[i]) {Chis_Least=Chis[i]; ambig_combine=i;}
2801 for(
int iHit=0;iHit<
n;iHit++){
2802 ambigList.push_back(select[ambig_combine][iHit]);
2808 tanl=chi_k[ambig_combine];
2809 z0=chi_b[ambig_combine];
2813void HoughValidUpdate::Combine(TH2D *h1,
int widthX,
int widthY,vector< vector < vector<int> > > vec_selectNum,M1 &peak_hit_list,M2 &peak_hit_num,
int &peak_track,vector<int> peakList[]){
2817 int npeak1=peak_track;
2818 vector<bool> peaktrack(npeak1,
true);
2828 int peakX=peakList[0][
n];
2829 int peakY=peakList[1][
n];
2830 for (
int px=peakX-widthX; px<=peakX+widthX; px++) {
2831 for (
int py=peakY-widthY; py<=peakY+widthY; py++) {
2833 if (px<0) { ax=px+binX; }
2834 else if (px>=binX) { ax=px-binX; }
2836 if ( (ax!=peakX || py!=peakY) && py>=0 && py<binY) Combine_two_cell(h1,peakX,peakY,ax,py,vec_selectNum,m,peak_hit_list,peak_hit_num);
2843 for(
int i=
n+1;i<npeak1;i++){
2844 if(peaktrack[i]==
false)
continue;
2845 int peaktheta=peakList[0][i];
2846 int peakrho=peakList[1][i];
2847 int peakhitNum=peakList[2][i];
2848 int count_same_hit=0;
2849 for(
int j=0;j<peakhitNum;j++){
2850 for(
int k=0;k<peak_hit_num[m];k++){
2851 if(vec_selectNum[peaktheta][peakrho][j]==peak_hit_list[m][k]){
2856 if(m_debug>1) cout<<
" pro: "<<
"peak: "<<i<<
" "<<(double)count_same_hit/peakhitNum<<endl;
2857 double f_hit=m_hit_pro;
2858 if(count_same_hit>f_hit*peakhitNum){
2863 for(
int i=
n+1;i<npeak1;i++){
2864 if(peaktrack[i]==
true){
2873 for(
int i=0;i<npeak1;i++){
2875 if(peaktrack[i]==
true){
2881void HoughValidUpdate::Combine_two_cell(TH2D *h1,
int xPeakCell,
int yPeakCell,
int xAround,
int yAround,vector< vector < vector<int> > > vec_selectNum,
int m,M1 &peak_hit_list,M2 &peak_hit_num){
2882 int size_of_around=vec_selectNum[xAround][yAround].size();
2883 if(size_of_around==0)
return;
2888 int size_of_peak=vec_selectNum[xPeakCell][yPeakCell].size();
2893 if(peak_hit_list[m].size()==0){
2894 for(
int inum=0;inum<size_of_peak;inum++){
2895 peak_hit_list[m][inum]=vec_selectNum[xPeakCell][yPeakCell][inum];
2898 vector<int> vec_more_select;
2899 for (
int i =0;i<size_of_around;i++){
2900 int same_vec_with_hitcombin=0;
2901 for(
int j= 0;j<peak_hit_list[m].size();j++){
2902 if(vec_selectNum[xAround][yAround][i]==peak_hit_list[m][j]){
2903 same_vec_with_hitcombin=1;
2907 if(same_vec_with_hitcombin==0) {
2909 vec_more_select.push_back(vec_selectNum[xAround][yAround][i]);
2912 int peak_hit_list_size=peak_hit_list[m].size();
2913 for(
int i=0;i<vec_more_select.size();i++ ){
2914 peak_hit_list[m][i+peak_hit_list_size]=vec_more_select[i];
2916 int peak_hit_list_size_new=peak_hit_list[m].size();
2917 peak_hit_num[m]=peak_hit_list_size_new;
2919 for(
int i= 0;i<peak_hit_list_size_new;i++){
2947int HoughValidUpdate::LeastLine(
int nhit,
double x[],
double y[],
double &k,
double &b,
double& chi2){
2953 for(
int i=0;i<nhit;i++){
2956 x2_sum=x2_sum+
x[i]*
x[i];
2957 y2_sum=y2_sum+y[i]*y[i];
2958 xy_sum=xy_sum+
x[i]*y[i];
2960 b=(x2_sum*y_sum-xy_sum*x_sum)/(nhit*x2_sum-x_sum*x_sum);
2961 k=(nhit*xy_sum-x_sum*y_sum)/(nhit*x2_sum-x_sum*x_sum);
2964 for(
int i=0;i<nhit;i++){
2967 if(yE[i]!=0) chi2_temp=(y[i]-yE[i])*(y[i]-yE[i])/yE[i]*yE[i];
HepGeom::Vector3D< double > HepVector3D
std::vector< MdcDigi * > MdcDigiVec
HepGeom::Point3D< double > HepPoint3D
bool compare(const HoughValidUpdate::Mytrack &a, const HoughValidUpdate::Mytrack &b)
double sin(const BesAngle a)
double cos(const BesAngle a)
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
const HepPoint3D ORIGIN
Constants.
**********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
bool compare(const HoughValidUpdate::Mytrack &a, const HoughValidUpdate::Mytrack &b)
double bFieldNominal() const
double cosTheta(void) const
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
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.
HoughValidUpdate(const std::string &name, ISvcLocator *pSvcLocator)
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)
void print(std::ostream &o) const
double driftTime(double tof, double z) const
void setCountPropTime(const bool count)
double driftDist(double, int, double, double, double) const
const MdcSWire * wire() const
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
void printRecMdcTrackCol() const
const Hep3Vector & zAxis(void) const
const HepPoint3D * getWestPoint(void) const
const HepPoint3D * getEastPoint(void) const
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 double chisq() const =0
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
hot_iterator begin() const
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
const TrkHotList & hotList() const
hot_iterator begin() const
virtual int nActive(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual void print(std::ostream &) const
const TrkFit * fitResult() const
virtual void printAll(std::ostream &) 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
Pair combine(Index i, Index j)
vector< int > vec_hit_on_trk