CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcHoughFinder/MdcHoughFinder-00-00-12/src/Hough.cxx
Go to the documentation of this file.
1#include "MdcHoughFinder/Hough.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/IPartPropSvc.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/IService.h"
10#include "GaudiKernel/NTuple.h"
11#include "GaudiKernel/INTupleSvc.h"
12#include "EventModel/EventHeader.h"
13#include "MdcRawEvent/MdcDigi.h"
14#include "Identifier/Identifier.h"
15#include "Identifier/MdcID.h"
16
17#include <iostream>
18#include <math.h>
19
20#include "EvTimeEvent/RecEsTime.h"
21#include "MdcGeom/EntranceAngle.h"
22#include "RawEvent/RawDataUtil.h"
23#include "MdcData/MdcHit.h"
24
25#include "McTruth/DecayMode.h"
26#include "McTruth/McParticle.h"
27#include "TrackUtil/Helix.h"
28#include "MdcRecoUtil/Pdt.h"
29
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/MdcRecoHitOnTrack.h"
39#include "MdcPrintSvc/IMdcPrintSvc.h"
40
41#include "MdcHoughFinder/HoughTrackList.h"
42#include "MdcHoughFinder/HoughTrack.h"
43#include <math.h>
44
45#include "EvTimeEvent/RecEsTime.h"
46//#include "MdcCalibFunSvc/IMdcCalibFunSvc.h"
47#include "McTruth/MdcMcHit.h"
48#include "TrkBase/TrkFit.h"
49#include "TrkBase/TrkHitList.h"
50#include "TrkBase/TrkExchangePar.h"
51#include "TrkFitter/TrkHelixMaker.h"
52#include "TrkFitter/TrkCircleMaker.h"
53#include "TrkFitter/TrkLineMaker.h"
54#include "TrkFitter/TrkHelixFitter.h"
55#include "MdcPrintSvc/IMdcPrintSvc.h"
56#include "MdcGeom/EntranceAngle.h"
57#include "TrackUtil/Helix.h"
58#include "GaudiKernel/IPartPropSvc.h"
59#include "MdcRecoUtil/Pdt.h"
60#include "RawEvent/RawDataUtil.h"
61#include "MdcData/MdcHit.h"
62#include "MdcTrkRecon/MdcMap.h"
63
64#include "TTree.h"
65#include "TH2D.h"
66
67#include "BesTimerSvc/IBesTimerSvc.h"
68#include "BesTimerSvc/BesTimerSvc.h"
69#include "BesTimerSvc/BesTimer.h"
70
71
72
73using namespace std;
74using namespace Event;
75
76MdcHoughFinder::MdcHoughFinder(const std::string& name, ISvcLocator* pSvcLocator) :
77 Algorithm(name, pSvcLocator)
78{
79 // Declare the properties
80 declareProperty("debug", m_debug = 0);
81 declareProperty("debugMap", m_debugMap = 0);
82 declareProperty("debug2D", m_debug2D = 0);
83 declareProperty("debugTrack", m_debugTrack = 0);
84 declareProperty("debugPeak", m_debugPeak = 0);
85 declareProperty("debugStereo", m_debugStereo= 0);
86 declareProperty("debugZs", m_debugZs= 0);
87 declareProperty("debug3D", m_debug3D= 0);
88 declareProperty("debugArbHit", m_debugArbHit= 0);
89 declareProperty("hist", m_hist = 0);
90 declareProperty("filter", m_filter= 0);
91 //read raw data setup
92 declareProperty("keepBadTdc", m_keepBadTdc = 0);
93 declareProperty("dropHot", m_dropHot= 0);
94 declareProperty("keepUnmatch", m_keepUnmatch = 0);
95 // combine pattsf
96 declareProperty("combineTracking",m_combineTracking = false);
97 declareProperty("removeBadTrack", m_removeBadTrack = 0);
98 declareProperty("dropTrkDrCut", m_dropTrkDrCut= 1.);
99 declareProperty("dropTrkDzCut", m_dropTrkDzCut= 10.);
100 declareProperty("dropTrkPtCut", m_dropTrkPtCut= 0.12);
101 declareProperty("dropTrkChi2Cut", m_dropTrkChi2Cut = 10000.);
102 //input setup
103 declareProperty("inputType", m_inputType = 0);
104 //set MdcHoughFinder map
105 declareProperty("mapCharge", m_mapCharge= -1); //0 use whole ; 1 only half
106 declareProperty("useHalf", m_useHalf= 0); //0 use whole ; 1 only half
107 declareProperty("mapHitStyle", m_mapHit= 0); //0 : all ; 1 :axial
108 declareProperty("nbinTheta", m_nBinTheta = 100);
109 declareProperty("nbinRho", m_nBinRho = 100);
110 declareProperty("rhoRange", m_rhoRange = 0.1);
111 declareProperty("peakWidth", m_peakWidth= 3);
112 declareProperty("peakHigh", m_peakHigh= 1);
113 declareProperty("hitPro", m_hitPro= 0.4);
114
115 declareProperty("recpos", m_recpos= 1);
116 declareProperty("recneg", m_recneg= 1);
117 declareProperty("combineSelf", m_combine= 1);
118 declareProperty("z0CutCompareHough", m_z0Cut_compareHough= 10);
119
120 //split drift circle
121 declareProperty("n1", m_npart= 100);
122 declareProperty("n2", m_n2= 30);
123
124 declareProperty("d1", m_d1= 0.2);
125 declareProperty("d2", m_d2= 0.2);
126
127 declareProperty("pdtFile", m_pdtFile = "pdt.table");
128 declareProperty("eventFile", m_evtFile= "EventList");
129
130 declareProperty("cgem", m_cgem=true);
131 declareProperty("skipMDCIT", m_skipMDCIT=true);
132 declareProperty("globalfit", m_globalfit=true);
133 declareProperty("zsRecMethod", m_recMethod=1);
134 declareProperty("factor2D", m_factor2D=5.0);
135 declareProperty("factor3D", m_factor3D=5.0);
136 declareProperty("cut2D", m_cut_2D);
137 declareProperty("cut3D", m_cut_3D);
138 declareProperty("maxGapLength", m_maxGapLength=99);
139 declareProperty("nHitDeleted", m_nHitDeleted=99);
140 declareProperty("nPoint3D", m_nPoint3D=5);
141 declareProperty("nPoint2D", m_nPoint2D=5);
142 declareProperty("nRMS", m_nRMS=3);
143 declareProperty("fillMap", m_fillMap=1);
144 declareProperty("printflag", m_printflag=0);
145 //declareProperty("cgemfit", m_cgemfit=1); //0:not fit, 1:fit both 2D and 3D , 2:fit 2D only , 3:fit 3D only
146
147}
148//
150 //Initailize MdcDetector
152 if(NULL == Global::m_gm) return StatusCode::FAILURE;
153
154 return StatusCode::SUCCESS;
155}
156
157// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
159
160 MsgStream log(msgSvc(), name());
161 log << MSG::INFO << "in initialize()" << endreq;
162
163 StatusCode sc;
164
165 //particle
166 IPartPropSvc* p_PartPropSvc;
167 static const bool CREATEIFNOTTHERE(true);
168 sc = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
169 if (!sc.isSuccess() || 0 == p_PartPropSvc) {
170 log << MSG::ERROR << " Could not initialize PartPropSvc" << endreq;
171 return sc;
172 }
173 m_particleTable = p_PartPropSvc->PDT();
174
175 // RawData
176 IRawDataProviderSvc* irawDataProviderSvc;
177 sc = service ("RawDataProviderSvc", irawDataProviderSvc);
178 m_rawDataProviderSvc = dynamic_cast<RawDataProviderSvc*> (irawDataProviderSvc);
179 if ( sc.isFailure() ){
180 log << MSG::FATAL << name()<<" Could not load RawDataProviderSvc!" << endreq;
181 return StatusCode::FAILURE;
182 }
183
184 // Geometry
185 IMdcGeomSvc* imdcGeomSvc;
186 sc = service ("MdcGeomSvc", imdcGeomSvc);
187 m_mdcGeomSvc = dynamic_cast<MdcGeomSvc*> (imdcGeomSvc);
188 if ( sc.isFailure() ){
189 log << MSG::FATAL << "Could not load MdcGeoSvc!" << endreq;
190 return StatusCode::FAILURE;
191 }
192
193 //---CGEM geometry
194 if(m_cgem){
195 ICgemGeomSvc* icgemGeomSvc;
196 sc = service ("CgemGeomSvc", icgemGeomSvc);
197 m_cgemGeomSvc = dynamic_cast<CgemGeomSvc*> (icgemGeomSvc);
198 if ( sc.isFailure() ){
199 log << MSG::FATAL << "Could not load CgemGeomSvc!" << endreq;
200 return StatusCode::FAILURE;
201 }
202 HoughHit::setCgemGeomSvc(m_cgemGeomSvc);
203 //CgemHitOnTrack::cgemGeomSvc = m_cgemGeomSvc;
204
205 ICgemCalibFunSvc* icgemCalibSvc;
206 sc = service ("CgemCalibFunSvc", icgemCalibSvc);
207 m_cgemCalibFunSvc = dynamic_cast<CgemCalibFunSvc*>(icgemCalibSvc);
208 if ( sc.isFailure() ){
209 log << MSG::FATAL << "Could not load CgemCalibFunSvc!" << endreq;
210 return StatusCode::FAILURE;
211 }
212
213 }
214
215 // magneticfield
216 sc = service ("MagneticFieldSvc",m_pIMF);
217 if(sc!=StatusCode::SUCCESS) {
218 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
219 }
220 m_bfield = new BField(m_pIMF);
221 log << MSG::INFO << "field z = "<<m_bfield->bFieldNominal()<< endreq;
222 m_context = new TrkContextEv(m_bfield);
223
224 //read pdt
225 Pdt::readMCppTable(m_pdtFile);
226
227 //Get MdcCalibFunSvc
228 IMdcCalibFunSvc* imdcCalibSvc;
229 sc = service ("MdcCalibFunSvc", imdcCalibSvc);
230 m_mdcCalibFunSvc = dynamic_cast<MdcCalibFunSvc*>(imdcCalibSvc);
231 if ( sc.isFailure() ){
232 log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endreq;
233 return StatusCode::FAILURE;
234 }
235
236 //initialize MdcPrintSvc
237 IMdcPrintSvc* imdcPrintSvc;
238 sc = service ("MdcPrintSvc", imdcPrintSvc);
239 m_mdcPrintSvc = dynamic_cast<MdcPrintSvc*> (imdcPrintSvc);
240 if ( sc.isFailure() ){
241 log << MSG::FATAL << "Could not load MdcPrintSvc!" << endreq;
242 return StatusCode::FAILURE;
243 }
244
245 //time
246 sc = service( "BesTimerSvc", m_timersvc);
247 if( sc.isFailure() ) {
248 log << MSG::WARNING << " Unable to locate BesTimerSvc" << endreq;
249 return StatusCode::FAILURE;
250 }
251 m_timer_all = m_timersvc->addItem("Execution");
252 m_timer_all->propName("nExecution");
253
254 //initialize static
255 HoughHit::setMdcCalibFunSvc(m_mdcCalibFunSvc);
256 HoughHit::setMdcGeomSvc(m_mdcGeomSvc);
257 HoughHit::setBunchTime(m_bunchT0);
258 Hough2D::setContext(m_context);
259 Hough2D::setCalib(m_mdcCalibFunSvc);
260 Hough2D::setCalib(m_cgemCalibFunSvc);
261 Hough2D::setGeomSvc(m_cgemGeomSvc);
262 //Hough2D::setcgemfitflag(m_cgemfit);
263 Hough3D::setContext(m_context);
264 Hough3D::setCalib(m_mdcCalibFunSvc);
265 Hough3D::setCalib(m_cgemCalibFunSvc);
266 Hough3D::setGeomSvc(m_cgemGeomSvc);
267 //Hough3D::setcgemfitflag(m_cgemfit);
268 HoughZsFit::setmethod(m_recMethod);
269
270 HoughHit::_npart=m_npart;
271 HoughMap::m_useHalfCir=m_useHalf;
272 HoughMap::m_N1=m_npart;
273 HoughMap::m_N2=m_n2;
274 HoughMap::m_nPoint2D=m_nPoint2D;
275 HoughMap::m_nRMS=m_nRMS;
276 HoughMap::m_method=m_fillMap;
277
280 HoughPeak::m_factor=m_factor2D;
282 HoughZsFit::m_factor=m_factor3D;
284 HoughZsFit::m_nPoint3D=m_nPoint3D;
285
286 if(m_debugMap> 0) HoughMap::m_debug = 1;
287 if(m_debug2D > 0) Hough2D::m_debug = 1;
288 if(m_debug3D > 0) Hough3D::m_debug = 1;
289 if(m_debugTrack> 0) HoughTrack::m_debug = 1;
290 if(m_globalfit> 0)HoughTrack::m_globalfit = 1;
291 if(m_debugPeak> 0) HoughPeak::m_debug = 1;
292 if(m_debugPeak> 0) HoughPeak::m_debug = 1;
293 if(m_debugStereo> 0)HoughStereo::m_debug = 1;
294 if(m_debugZs> 0) HoughZsFit::m_debug = 1;
295 //if(m_recMethod> 0) HoughZsFit::m_recMethod = 1;
296 if(m_debug3D > 4) TrkHelixFitter::m_debug = 1;
297
298 if(m_hist) sc = bookTuple();
299 if ( sc.isFailure() ){
300 log << MSG::FATAL << "Could not book Tuple !" << endreq;
301 return StatusCode::FAILURE;
302 }
303 return StatusCode::SUCCESS;
304}
305
306// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
308
309 MsgStream log(msgSvc(), name());
310 log << MSG::INFO << "in execute()" << endreq;
311 cout.precision(6);
312
313
314 m_timer_all->start();
315
316 //event start time
317 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
318 if (!evTimeCol) {
319 //log << MSG::WARNING<< "Could not retrieve RecEsTimeCol , use t0=0" << endreq;
320 //m_bunchT0=0.;
321 log << MSG::WARNING<< "Could not retrieve RecEsTimeCol" << endreq;
322 return StatusCode::SUCCESS;
323 }else{
324 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
325 if (iter_evt != evTimeCol->end()){
326 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;//m_bunchT0-s, getTest-ns
327 }
328 }
329 HoughHit::setBunchTime(m_bunchT0);
330
331 //-- Get the event header, print out event and run number
332 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
333 if (!eventHeader) {
334 log << MSG::FATAL << "Could not find Event Header" << endreq;
335 return StatusCode::FAILURE;
336 }
337
338 //-- Get CGEM cluster
339 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(), "/Event/Recon/RecCgemClusterCol");
340 if(m_cgem){
341 if (!recCgemClusterCol){
342 log << MSG::WARNING << "Could not retrieve Cgem cluster list" << endreq;
343 return StatusCode::FAILURE;
344 }
345 }
346
347 m_event=eventHeader->eventNumber();
348 m_run=eventHeader->runNumber();
349 if(m_debug>0) cout<<"begin evt "<<eventHeader->eventNumber()<<endl;
350 if(m_event%1000==0) cout << " run No: "<< m_run << " event No: " << m_event << endl;
351
352 //prepare tds
353 RecMdcTrackCol* trackList_tds;
354 RecMdcHitCol* hitList_tds;
355 vector<RecMdcTrack*> vec_trackPatTds;
356 int nTdsTk = storeTracks(trackList_tds,hitList_tds,vec_trackPatTds);
357 //print track in pattsf with bad vertex
358 if(m_debug>0){
359 RecMdcTrackCol::iterator iteritrk_pattsf = vec_trackPatTds.begin();
360 for(;iteritrk_pattsf!=vec_trackPatTds.end();iteritrk_pattsf++){
361 cout<<"in PATTSF LOST: "<<(*iteritrk_pattsf)->helix(0)<<" "<<(*iteritrk_pattsf)->helix(1)<<" "<<(*iteritrk_pattsf)->helix(2)<<" "<<(*iteritrk_pattsf)->helix(3)<<" "<<(*iteritrk_pattsf)->helix(4)<<" chi2 "<<(*iteritrk_pattsf)->chi2()<<endl;
362 }
363 }
364
365 //for arbi hits
366 MdcTrackParams m_par;
367 if(m_debugArbHit>0 ) m_par.lPrint=8;
368 m_par.lRemoveInActive=1;
369 //m_par.lUseQualCuts=0;
370 m_par.maxGapLength=m_maxGapLength;
371 m_par.nHitDeleted=m_nHitDeleted;
372 //m_par.maxChisq=99;
373 //m_par.minHits=99;
374
375 // if filter read eventNum in file
376 if(m_filter){
377 ifstream lowPt_Evt;
378 lowPt_Evt.open(m_evtFile.c_str());
379 vector<int> evtlist;
380 int evtNum;
381 while( lowPt_Evt >> evtNum) {
382 evtlist.push_back(evtNum);
383 }
384 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),m_event);
385 if( iter_evt == evtlist.end() ) { setFilterPassed(false); return StatusCode::SUCCESS; }
386 else setFilterPassed(true);
387 }
388 //m_printflag = 0;
389 if(m_printflag==1)cout<<"Begin Event ============================================================================================================== "<<eventHeader->eventNumber()<<endl;
390
391 if(m_inputType == -1) GetMcInfo();
392
393 //-- Get MDC digi vector
394 if(m_debug>0) cout<<"step1 : prepare digi "<<endl;
395 MdcDigiVec mdcDigiVec = prepareDigi();
396
397 //-- Create MdcHoughFinder hit list
398 bool debugTruth = false;
399 if(m_inputType == -1) debugTruth= true;
400 if(m_debug>0) cout<<"step2 : hits-> hough hit list "<<endl;
401 HoughHitList houghHitList(mdcDigiVec);
402 if(m_cgem) houghHitList.addCgemClusterList(recCgemClusterCol); // add CGEM cluster
403 //houghHitList.print();
404 //if(m_cgem) houghHitList.addCgemClusterList(); // add CGEM cluster
405 // if( mdcDigiVec.size() < 10 ) return StatusCode::SUCCESS;
406 if( houghHitList.nHit() < 10 || houghHitList.nHit()>500 ) return StatusCode::SUCCESS;
407 if(debugTruth) houghHitList.addTruthInfo(g_tkParTruth);
408 if(m_hist) dumpHoughHitList(houghHitList);
409 if(m_debug>0) houghHitList.printAll();
410
411 vector<MdcHit*> mdcHitCol_neg;
412 vector<MdcHit*> mdcHitCol_pos;
413 MdcDigiVec::iterator iter = mdcDigiVec.begin();
414 for (;iter != mdcDigiVec.end(); iter++) {
415 const MdcDigi* digi = (*iter);
416 if( HoughHit(digi).driftTime()>1000 || HoughHit(digi).driftTime()<=0 ) continue;
417 MdcHit *mdcHit= new MdcHit(digi, Global::m_gm);
418 MdcHit *mdcHit_pos= new MdcHit(digi, Global::m_gm);
419 mdcHitCol_neg.push_back(mdcHit);
420 mdcHitCol_pos.push_back(mdcHit_pos);
421 }
422
423 HoughMap *m_map = new HoughMap(-1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);//, 2dOr3d);
424
425 //m_map->printPeak();
426 //m_map->printTrack();
427 //if(m_hist) m_nHit = houghHitList.nHit();
428 //if(m_hist) dumpHoughMap(*m_map);
429
430 //track
431 if(m_debug>0) cout<<"step3 : neg track list "<<endl;
432 vector<HoughTrack*> vec_track_neg;
433 vector<HoughTrack*> vec_track2D_neg;
434 MdcTrackList mdcTrackList_neg(m_par) ;
435 if(m_recneg){
436 HoughTrackList trackList_neg(*m_map);
437 int trackList_size = trackList_neg.getTrackNum();
438 vector< vector<int> > stat_2d(2,vector<int>(trackList_size,0) );
439 vector< vector<int> > stat_3d(2,vector<int>(trackList_size,0) );
440 //int ifit=0;
441 //int ifit3D=0;
442 if(m_printflag==1)cout<<"----------------------------------------------------------------------------------------------------"<<endl;
443 if(m_printflag==1)cout<<" suppose charge negetive,ntracks: "<<trackList_size<<endl;
444 for(int itrack=0;itrack<trackList_size;itrack++){
445 if(m_debug>0) cout<<"begin track: "<<itrack<<endl;
446 if(m_printflag==1)cout<<endl;
447 if(m_printflag==1)cout<<"begin track: "<<itrack<<endl;
448 //suppose charge -
449 if(m_debug>0) cout<<" suppose charge -1 "<<endl;
450 HoughTrack &track_neg = trackList_neg.getTrack(itrack);
451 track_neg.setMdcHit( &mdcHitCol_neg);
452 track_neg.setHoughHitList(houghHitList.getList());
453 track_neg.setCharge(-1);
454 track_neg.setMcPar(g_tkParTruth);
455 track_neg.setbunchTime(m_bunchT0);
456 track_neg.fitLeast();
457 if(m_printflag==1)cout<<"---before 2D fitting---"<<endl;
458 if(m_printflag==1)track_neg.printHoughTrack();
459 stat_2d[0][itrack] = track_neg.fit2D(m_bunchT0);
460 int track_charge_2d = track_neg.trackCharge2D();
461 if(m_debug>0) cout<<" charge -1 stat2d "<<stat_2d[0][itrack]<<" "<<track_charge_2d<<endl;
462 //cout<<" charge stat2d "<<stat_2d[0][itrack]<<" "<<track_charge_2d<<endl;
463 if( stat_2d[0][itrack] == 0 || track_charge_2d ==0 ){
464 if( stat_2d[0][itrack] == 0 && m_printflag==1)cout<<"==============================> 2D fit fail"<<endl;
465 if(track_charge_2d ==0 && m_printflag==1)cout<<"==============================> 2D charge wrong"<<endl;
466 continue;
467 }
468
469 if(m_hist==2)dumpHoughTrack(track_neg,itrack,trackList_size);
470 if(m_hist==2)dumpHitOnTrack(track_neg);
471 //vec_track2D_neg.push_back( &track_neg );
472 //fill 2D inf
473 //ifit++;
474 //3D fit
475 int nHit3d = track_neg.find_stereo_hit();
476 int npair= track_neg.find_pair_hit();
477 //cout<<"npair "<<npair<<endl;
478
479 int track_charge_3d = track_neg.trackCharge3D();
480 if(m_debug>0) cout<<" nhitstereo -1 "<<nHit3d<<" "<<track_charge_3d<<endl;
481 //cout<<" nhitstereo "<<nHit3d<<" "<<track_charge_3d<<endl;
482 if( nHit3d <3 || track_charge_3d==0 ){
483 if(nHit3d <3 && m_printflag==1)cout<<"==============================> stereo hit <3"<<endl;
484 if(track_charge_3d==0 && m_printflag==1)cout<<"==============================> 3D charge wrong"<<endl;
485 continue;
486 }
487
488 //choose fit method
489 if( npair==0 ) stat_3d[0][itrack] = track_neg.fit3D();
490 else stat_3d[0][itrack] = track_neg.fit3D_inner();
491 //else stat_3d[0][itrack] = track_neg.fit3D();
492
493 if(m_debug>0) cout<<" charge -1 stat3d "<<stat_3d[0][itrack]<<" "<<endl;
494 //cout<<" charge stat3d "<<stat_3d[0][itrack]<<" "<<endl;
495 if( stat_3d[0][itrack]==0 ){
496 if(m_printflag==1)cout<<"==============================> 3D fit fail"<<endl;
497 continue;
498 }
499 vec_track_neg.push_back( &track_neg );
500 //fill 3D inf
501 if(m_hist==3)dumpHoughTrack(track_neg,itrack,trackList_size);
502 if(m_hist==3)dumpHitOnTrack(track_neg);
503 //track_neg.printRecHit();
504
505 }
506
507 std::sort ( vec_track_neg.begin(),vec_track_neg.end(),more_pt);
508 if(m_globalfit){
509 if(m_printflag==1)cout<<"tracks before fitting: "<<trackList_neg.getTrackNum()<<endl<<"tracks after fittng: "<<vec_track_neg.size()<<endl;
510 //track for clear
511 vector<MdcTrack*> vec_MdcTrack_neg;
512 for( unsigned int i =0;i<vec_track_neg.size();i++){
513 MdcTrack *mdcTrack = new MdcTrack(vec_track_neg[i]->getTrk());
514 vec_MdcTrack_neg.push_back(mdcTrack);
515 if(m_debug>0) cout<<"trackneg: "<<i<<" pt "<<vec_track_neg[i]->getPt3D()<<endl;
516 if(m_debug>0) vec_track_neg[i]->print();
517 if(m_printflag==1)vec_track_neg[i]->getTrk()->printAll(std::cout);
518 }
519 if(m_debug>0) cout<<"step4 : judge neg track list "<<endl;
520 int nDeleted = judgeHit(mdcTrackList_neg,vec_MdcTrack_neg);
521 if(m_printflag==1)cout<<"tracks before judge hits: "<<vec_MdcTrack_neg.size()<<endl;
522 //printTrack(vec_MdcTrack_neg);
523 if(m_printflag==1)cout<<"tracks after judge hits: "<<mdcTrackList_neg.length()<<endl;
524 if(m_printflag==1)printTrack(mdcTrackList_neg);
525 //if(nDeleted>0)cout<<nDeleted<<" tracks have been deleted by MdcTrackList.arbitrateHits()"<<endl;
526 if(m_debug>0 && nDeleted>0)cout<<nDeleted<<" tracks have been deleted by MdcTrackList.arbitrateHits()"<<endl;
527 if(m_debug>0) cout<<"finish - charge "<<endl;
528 }else{
529 storeTracks(trackList_tds, hitList_tds, trackList_neg);
530 }
531 }
532
533 //do rec pos charge
534
535 HoughMap *m_map2 = new HoughMap(1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);//, 2dOr3d);
536 if(m_debug>0) cout<<"step5 : pos track list "<<endl;
537 vector<HoughTrack*> vec_track_pos;
538 MdcTrackList mdcTrackList_pos(m_par) ;
539 if(m_recpos){
540 HoughTrackList tracklist_pos(*m_map2);
541 int tracklist_size2 = tracklist_pos.getTrackNum();
542 vector< vector<int> > stat_2d2(2,vector<int>(tracklist_size2,0) );
543 vector< vector<int> > stat_3d2(2,vector<int>(tracklist_size2,0) );
544 //int ifit=0;
545 //int ifit3D=0;
546 if(m_printflag==1)cout<<endl<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
547 if(m_printflag==1)cout<<" suppose charge positive,ntracks: "<<tracklist_size2<<endl;
548 for(int itrack=0;itrack<tracklist_size2;itrack++){
549 if(m_printflag==1)cout<<endl;
550 if(m_printflag==1)cout<<"begin track: "<<itrack<<endl;
551 //suppose charge +
552 if(m_debug>0) cout<<" suppose charge +1 "<<endl;
553 HoughTrack &track_pos = tracklist_pos.getTrack(itrack);
554 //track_pos.setMdcHit( &mdcHitCol_pos);
555 track_pos.setMdcHit( &mdcHitCol_neg);
556 track_pos.setHoughHitList(houghHitList.getList());
557 track_pos.setCharge(1);
558 track_pos.setMcPar(g_tkParTruth);
559 track_pos.setbunchTime(m_bunchT0);
560 track_pos.fitLeast();
561 if(m_printflag==1)cout<<"---before 2D fitting---"<<endl;
562 if(m_printflag==1)track_pos.printHoughTrack();
563 stat_2d2[0][itrack] = track_pos.fit2D(m_bunchT0);
564 int track_charge_2d = track_pos.trackCharge2D();
565 if(m_debug>0) cout<<" charge +1 stat2d "<<stat_2d2[0][itrack]<<" "<<track_charge_2d<<endl;
566 if( stat_2d2[0][itrack] == 0 || track_charge_2d==0 ){
567 if( stat_2d2[0][itrack] == 0 && m_printflag==1)cout<<"==============================> 2D fit fail"<<endl;
568 if(track_charge_2d ==0 && m_printflag==1)cout<<"==============================> 2D charge wrong"<<endl;
569 continue;
570 }
571 //fill 2d inf
572 //ifit++;
573 //3d fit
574 int nHit3d = track_pos.find_stereo_hit();
575 int npair= track_pos.find_pair_hit();
576 //cout<<"npair "<<npair<<endl;
577
578 int track_charge_3d = track_pos.trackCharge3D();
579 if(m_debug>0) cout<<" nhitstereo +1 "<<nHit3d<<" "<<track_charge_3d<<endl;
580 if( nHit3d <3 || track_pos.trackCharge3D()==0 ){
581 if(nHit3d <3 && m_printflag==1)cout<<"==============================> stereo hit <3"<<endl;
582 if(track_charge_3d==0 && m_printflag==1)cout<<"==============================> 3D charge wrong"<<endl;
583 continue;
584 }
585 //choose fit method
586 if( npair==0 ) stat_3d2[0][itrack] = track_pos.fit3D();
587 else stat_3d2[0][itrack] = track_pos.fit3D_inner();
588 //else stat_3d2[0][itrack] = track_neg.fit3D();
589 //dumpHitOnTrack(track_pos);
590
591 if(m_debug>0) cout<<" charge +1 stat3d "<<stat_3d2[0][itrack]<<" "<<endl;
592 if( stat_3d2[0][itrack]==0 ){
593 if(m_printflag==1)cout<<"==============================> 3D fit fail"<<endl;
594 continue;
595 }
596 vec_track_pos.push_back( &track_pos );
597 //track_pos.printRecHit();
598 //fill 3d inf
599 //ifit3D++;
600 //dumpHoughTrack(track_pos,itrack,tracklist_size2);
601 }
602
603 //sort pos tracklist
604 std::sort ( vec_track_pos.begin(),vec_track_pos.end(),more_pt);
605
606 // clear pos track
607 if(m_globalfit){
608 if(m_printflag==1)cout<<"tracks before fitting: "<<tracklist_pos.getTrackNum()<<endl<<"tracks after fittng: "<<vec_track_pos.size()<<endl;
609 vector<MdcTrack*> vec_MdcTrack_pos;
610 for( unsigned int i =0;i<vec_track_pos.size();i++){
611 MdcTrack *mdcTrack = new MdcTrack(vec_track_pos[i]->getTrk());
612 vec_MdcTrack_pos.push_back(mdcTrack);
613 if(m_debug>0) cout<<"trackpos : "<<i<<" pt "<<vec_track_pos[i]->getPt3D()<<endl;
614 if(m_debug>0) vec_track_pos[i]->print();
615 if(m_printflag==1)vec_track_pos[i]->getTrk()->printAll(std::cout);
616 }
617 if(m_debug>0) cout<<"step6 : judge pos track list "<<endl;
618 int nDeleted = judgeHit(mdcTrackList_pos,vec_MdcTrack_pos);
619 if(m_printflag==1)cout<<"tracks before judge hits: "<<vec_MdcTrack_pos.size()<<endl;
620 //printTrack(vec_MdcTrack_pos);
621 if(m_printflag==1)cout<<"tracks after judge hits: "<<mdcTrackList_pos.length()<<endl;
622 if(m_printflag==1)printTrack(mdcTrackList_pos);
623 //if(nDeleted>0)cout<<nDeleted<<" tracks have been deleted by MdcTrackList.arbitrateHits()"<<endl;
624 if(m_debug>0 && nDeleted>0)cout<<nDeleted<<" tracks have been deleted by MdcTrackList.arbitrateHits()"<<endl;
625
626 }else{
627 storeTracks(trackList_tds, hitList_tds, tracklist_pos);
628 }
629 }
630
631 if(m_globalfit){
632 //combine hough itself
633 // if(m_debug>0) cout<<"step7 : combine neg&pos track list "<<endl;
634 if(m_printflag==1)cout<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
635 if(m_printflag==1)cout<<endl<<"-/+tracks before merge: "<<mdcTrackList_neg.length()<<" "<<mdcTrackList_pos.length()<<endl;
636 if(m_printflag==1)printTrack(mdcTrackList_neg);
637 if(m_printflag==1)printTrack(mdcTrackList_pos);
638 if(m_combine){
639 compareHough(mdcTrackList_neg);
640 compareHough(mdcTrackList_pos);
641 }
642 if(m_printflag==1)cout<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
643 if(m_printflag==1)cout<<"-/+tracks after merge: "<<mdcTrackList_neg.length()<<" "<<mdcTrackList_pos.length()<<endl;
644 if(m_printflag==1)printTrack(mdcTrackList_neg);
645 if(m_printflag==1)printTrack(mdcTrackList_pos);
646 if( mdcTrackList_neg.length()!=0 && mdcTrackList_pos.length()!=0 ) judgeChargeTrack(mdcTrackList_neg,mdcTrackList_pos);
647 if(m_printflag==1)cout<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
648 if(m_printflag==1)cout<<"tracks after -/+ judge: "<<mdcTrackList_neg.length()<<" "<<mdcTrackList_pos.length()<<endl;
649 if(m_printflag==1)printTrack(mdcTrackList_neg);
650 if(m_printflag==1)printTrack(mdcTrackList_pos);
651 //cout<<"pos "<<mdcTrackList_pos.length()<<endl;
652 //cout<<"neg "<<mdcTrackList_neg.length()<<endl;
653 //add tracklist
654 mdcTrackList_neg+=mdcTrackList_pos; //neg -> all charge
655 //if(m_cgem || m_skipMDCIT)mdcTrackList_neg.setNoInner(true);
656 //MdcTrackParams new_par;
657 //new_par.lPrint=8;
658 //mdcTrackList_neg.newParams(new_par);
659 int nDeleted = mdcTrackList_neg.arbitrateHits();
660 if(m_printflag==1)cout<<endl<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
661 if(m_printflag==1 && nDeleted>0)cout<<nDeleted<<" tracks have been deleted by MdcTrackList.arbitrateHits()"<<endl;
662 if(m_printflag==1)cout<<"event:"<<eventHeader->eventNumber()<<" "<<"total tracks: "<<mdcTrackList_neg.length()<<endl<<endl;
663 if(m_printflag==1)printTrack(mdcTrackList_neg);
664
665 //compare pattsf&hough self
666 if(m_combineTracking) nTdsTk = comparePatTsf(mdcTrackList_neg,trackList_tds);
667
668 // store tds
669 if(m_debug>0) cout<<"step8 : store tds "<<endl;
670 if(m_debug>0) cout<<"store tds "<<endl;
671 int tkId = nTdsTk ; //trkid
672 for( unsigned int i =0;i<mdcTrackList_neg.length();i++){
673 if(m_debug>0) cout<<"- charge size i : "<<i<<" "<<mdcTrackList_neg.length()<<endl;
674 int tkStat = 4;//track find by houghspace set stat=4
675 mdcTrackList_neg[i]->storeTrack(tkId, trackList_tds, hitList_tds, tkStat);
676 tkId++;
677 delete mdcTrackList_neg[i];
678 }
679 }
680 if(m_debug>0) m_mdcPrintSvc->printRecMdcTrackCol();
681
682 m_timer_all->stop();
683 double t_teventTime = m_timer_all->elapsed();
684 //RecMdcTrackCol::iterator iteritrk = trackList_tds->begin();
685 //for(;iteritrk!=trackList_tds->end();iteritrk++){
686 //cout<<"nlayer:"<<(*iteritrk)->nlayer()<<endl;
687 //}
688 if(m_hist==1)dumpHoughTrack(trackList_tds);
689 if(m_hist==1)dumpHitOnTrack(trackList_tds);
690
691 if(m_hist)ntuple_hit->write();
692 if(m_hist)ntuple_trk->write();
693 delete m_map;
694 delete m_map2;
695 if(m_debug>0) cout<<"after delete map "<<endl;
696 for(int ihit=0;ihit<mdcHitCol_neg.size();ihit++){
697 delete mdcHitCol_neg[ihit];
698 delete mdcHitCol_pos[ihit];
699 }
700
701 if(m_debug>0) cout<<"after delete hit"<<endl;
702 //clearMem(mdcTrackList_neg,mdcTrackList_pos);
703 if(m_debug>0) cout<<"end event "<<endl;
704
705 return StatusCode::SUCCESS;
706}
707
708// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
710 MsgStream log(msgSvc(), name());
711 delete m_bfield ;
712 log << MSG::INFO<< "in finalize()" << endreq;
713
714 return StatusCode::SUCCESS;
715}
716
717int MdcHoughFinder::GetMcInfo(){
718 MsgStream log(msgSvc(), name());
719 StatusCode sc;
720 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
721 if (!mcParticleCol) {
722 log << MSG::ERROR << "Could not find McParticle" << endreq;
723 return StatusCode::FAILURE;
724 }
725
726
727 g_tkParTruth.clear();//clear track param.
728
729 //t_t0Truth=-1;
730 int t_qTruth = 0;
731 int t_pidTruth = -999;
732 int nMcTk=0;
733 McParticleCol::iterator iter_mc = mcParticleCol->begin();
734 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
735 //cout<<"trackid: "<<setw(4)<<(*iter_mc)->trackIndex()<<" "
736 //<<setw(8)<<(*iter_mc)->particleProperty()<<" "
737 //<<(*iter_mc)->primaryParticle()<<" "
738 //<<(*iter_mc)->leafParticle()<<" "
739 //<<(*iter_mc)->decayFromGenerator()<<" "
740 //<<(*iter_mc)->decayInFlight()<<" "
741 //<<endl;
742 t_pidTruth = (*iter_mc)->particleProperty();
743 //if(!(*iter_mc)->primaryParticle()) continue;
744 if((*iter_mc)->primaryParticle()) continue;
745 if(!(*iter_mc)->decayFromGenerator()) continue;
746 if(!((*iter_mc)->particleProperty() == 211 || (*iter_mc)->particleProperty() == -211 || (*iter_mc)->particleProperty() == 11 ||(*iter_mc)->particleProperty() == -11))continue;
747 //if((m_pid!=0) && (t_pidTruth != m_pid)){ continue; }
748 //t_t0Truth=(*iter_mc)->initialPosition().t();
749 std::string name;
750 int pid = t_pidTruth;
751 if( pid == 0 ) {
752 log << MSG::WARNING << "Wrong particle id" <<endreq;
753 continue;
754 }else{
755 IPartPropSvc* p_PartPropSvc;
756 static const bool CREATEIFNOTTHERE(true);
757 StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
758 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
759 std::cout<< " Could not initialize Particle Properties Service" << std::endl;
760 }
761 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
762 if( p_particleTable->particle(pid) ){
763 name = p_particleTable->particle(pid)->name();
764 t_qTruth = p_particleTable->particle(pid)->charge();
765 }else if( p_particleTable->particle(-pid) ){
766 name = "anti " + p_particleTable->particle(-pid)->name();
767 t_qTruth = (-1)*p_particleTable->particle(-pid)->charge();
768 }
769 }
770 t_q = t_qTruth;
771 //cout<<"decay: "<<(*iter_mc)->decayInFlight()<<endl;
772
773 //helix
774 if(m_debug>1) std::cout<<__FILE__<<" "<<__LINE__<<" new helix with pos "<<(*iter_mc)->initialPosition().v()<<" mom "<<(*iter_mc)->initialFourMomentum().v()<<" q "<<t_qTruth<<std::endl;
775 Helix mchelix = Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);//cm
776 mchelix.pivot( HepPoint3D(0.,0.,0.) );
777 //m_helix = &mchelix;
778 m_helix = new Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);
779 m_helix->pivot( HepPoint3D(0.,0.,0.) );
780 //m_helix = &(Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth));//cm;
781
782 int mcTkId = (*iter_mc)->trackIndex();
783
784 pair<int, const HepVector> p(mcTkId,mchelix.a());
785 g_tkParTruth.insert(p);
786 // exchange to rho theta test negtive charge
787 double rho , theta;
788 if( mchelix.phi0()>M_PI) { rho=t_qTruth/fabs(mchelix.radius()); theta = mchelix.phi0()-M_PI;}
789 else {rho =-1.*t_qTruth/fabs(mchelix.radius()) ; theta = mchelix.phi0();}
790 t_d0=-mchelix.dr();
791 t_z0=mchelix.dz();
792 t_pt=mchelix.pt();
793 t_p=mchelix.momentum(0.).mag();
794 t_tanl=mchelix.tanl();
795 t_cos= mchelix.cosTheta();
796
797 //m_pzTruth[nMcTk]=mchelix.momentum(0.).z();
798 //m_pidTruth[nMcTk] = t_pidTruth;
799 //m_costaTruth[nMcTk] = mchelix.cosTheta();
800 //m_ptTruth[nMcTk] = mchelix.pt();
801 //m_pTruth[nMcTk] = mchelix.momentum(0.).mag();
802 //m_qTruth[nMcTk] = t_qTruth;
803 //m_drTruth[nMcTk] = mchelix.dr();
804 //m_phi0Truth[nMcTk] = mchelix.phi0();
805 //m_omegaTruth[nMcTk] =1./(mchelix.radius()); //Q
806 //m_dzTruth[nMcTk] = mchelix.dz();
807 //m_tanl_mc[nMcTk] =mchelix.tanl();
808 //m_rho_mc[nMcTk] = rho;
809 //m_theta_mc[nMcTk] = theta;
810
811
812 double phi0 = mchelix.phi0()+M_PI/2;
813 while(phi0> M_PI)phi0-=2*M_PI;
814 while(phi0<-M_PI)phi0+=2*M_PI;
815
816 if(m_printflag==1){
817 cout<<" charge "<<t_qTruth<<endl;
818 double rho = fabs(mchelix.kappa()/333.567);
819 double theta = atan2((mchelix.dr()-(333.567/mchelix.kappa()))*sin(mchelix.phi0()),(mchelix.dr()-(333.567/mchelix.kappa()))*cos(mchelix.phi0()));
820 if(theta<0){theta+=M_PI;rho=-rho;}
821 cout<<"(Xc, Yc, R):"<<"("<<(mchelix.dr()-(333.567/mchelix.kappa()))*cos(mchelix.phi0())<<", "<<(mchelix.dr()-(333.567/mchelix.kappa()))*sin(mchelix.phi0())<<", "<<(-333.567/mchelix.kappa())<<") (theta,rho):"<<"("<<theta<<", "<<rho<<") ,pt="<<1./mchelix.kappa()<<endl;
822 cout<<"truth barbar: "<<setw(15)<<-mchelix.dr()<<setw(15)<<phi0<<setw(15)<<mchelix.kappa()/333.567<<setw(15)<<mchelix.dz()<<setw(15)<<mchelix.tanl()<<endl;
823 cout<<"truth besIII: "<<setw(15)<<mchelix.dr()<<setw(15)<<mchelix.phi0()<<setw(15)<<mchelix.kappa()<<setw(15)<<mchelix.dz()<<setw(15)<<mchelix.tanl()<<endl;
824 cout<<endl;
825 }
826 t_phi = phi0;
827 t_omega = mchelix.kappa()/333.567;
828 // if(m_debug>0){
829 // std::cout<<"Truth tk "<<nMcTk<<" " <<name<<" pid "<<pid<<" charge "<<t_qTruth << " helix "<< mchelix.a()<<" p "<<mchelix.momentum(0.)<<" p "<<mchelix.momentum(0.).mag()<<" pt "<<mchelix.momentum(0.).perp()<<" pz "<<mchelix.momentum(0.).z()<<std::endl;
830 //
831 // cout<<"ptTruth "<<mchelix.pt()<<endl;
832 // cout<<"tanlTruth"<<mchelix.tanl()<<endl;
833 // cout<<"d0Truth"<<mchelix.dr()<<endl;
834 // }
835 // nMcTk++;
836 }
837 // m_nTrkMC = nMcTk;
838 //if(m_debug>2) m_mdcPrintSvc->printMdcMcHitCol();
839
840 g_firstHit.set(0,0,0);
841 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc(),"/Event/MC/MdcMcHitCol");
842 if(mdcMcHitCol){
843 //cout<<"size:"<<mdcMcHitCol->size()<<endl;
844 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
845 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++) {
846 const Identifier id= (*iter_mchit)->identify();
847 int l = MdcID::layer(id);
848 int w = MdcID::wire(id);
849 //cout<<"MDC trackID: "<<(*iter_mchit)->getTrackIndex()<<" layer: "<<l<<" wire: "<<w<<endl;
850 if((*iter_mchit)->getTrackIndex()==0) {
851 g_firstHit.setX((*iter_mchit)->getPositionX()/10.);//mm to cm
852 g_firstHit.setY((*iter_mchit)->getPositionY()/10.);
853 g_firstHit.setZ((*iter_mchit)->getPositionZ()/10.);
854 //break;
855 }
856 }
857 }else{
858 std::cout<<__FILE__<<" Could not get MdcMcHitCol "<<std::endl;
859 return StatusCode::FAILURE;
860 }
861
862 //add truth info. to HoughHit in list
863 return StatusCode::SUCCESS;
864}
865
866MdcDigiVec MdcHoughFinder::prepareDigi(){
867 // retrieve Mdc digi vector form RawDataProviderSvc
868 uint32_t getDigiFlag = 0;
869 if(m_dropHot || m_combineTracking )getDigiFlag |= MdcRawDataProvider::b_dropHot;
870 if(m_keepBadTdc) getDigiFlag |= MdcRawDataProvider::b_keepBadTdc;
871 if(m_keepUnmatch) getDigiFlag |= MdcRawDataProvider::b_keepUnmatch;
872
873 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec(getDigiFlag);
874 return mdcDigiVec;
875}
876
877void MdcHoughFinder::dumpHoughHitList(const HoughHitList& houghhitlist){
878
879 m_hit_run = m_run;
880 m_hit_evt = m_event;
881 m_hit_nhit = houghhitlist.nHit();
882 std::vector<HoughHit>::const_iterator iter = houghhitlist.getList().begin();
883 for(int iHit=0;iter!= houghhitlist.getList().end(); iter++,iHit++){
884 const HoughHit h = (*iter);
885 if( m_debug>0 ) h.printTruth();
886 m_hit_hitid[iHit] = h.getHitId();
887 m_hit_layer[iHit] = h.getLayerId();
888 m_hit_wire[iHit] = h.getWireId();
889 m_hit_x[iHit] = h.getMidX();
890 m_hit_y[iHit] = h.getMidY();
891 m_hit_z[iHit] = h.getMidPoint().z();
892 m_hit_driftdist[iHit] = h.getDriftDist();
893 m_hit_drifttime[iHit] = h.getDriftTime();
894 m_hit_flag[iHit] = h.getSlayerType();
895 m_hit_truth_x[iHit] = h.getXTruth();
896 m_hit_truth_y[iHit] = h.getYTruth();
897 m_hit_truth_z[iHit] = h.getZTruth();
898 m_hit_truth_drift[iHit] = h.getDriftDistTruth();
899 m_hit_truth_ambig[iHit] = h.getLrTruth();
900 }
901 // m_nHit = houghhitlist.nHit();
902}
903void MdcHoughFinder::dumpHitOnTrack( HoughTrack& houghTrack){
904 std::vector<HoughRecHit> recHitVec = houghTrack.getHoughHitList();
905 m_hot_run = m_run;
906 m_hot_evt = m_event;
907 m_hot_trk = houghTrack.getTrkid();
908 m_hot_nhot = recHitVec.size();
909 std::vector<HoughRecHit>::const_iterator iter = recHitVec.begin();
910 for(int iHit=0;iter!= recHitVec.end(); iter++,iHit++){
911 const HoughRecHit h = (*iter);
912 if( m_debug>0 ) h.printTruth();
913 m_hot_hitid[iHit] = h.getHitId();
914 m_hot_layer[iHit] = h.getLayerId();
915 m_hot_wire[iHit] = h.getWireId();
916 m_hot_x[iHit] = h.getMidX();
917 m_hot_y[iHit] = h.getMidY();
918 m_hot_z[iHit] = h.getMidPoint().z();
919 m_hot_x0[iHit] = h.getLeftPoint().x();
920 m_hot_y0[iHit] = h.getLeftPoint().y();
921 m_hot_z0[iHit] = h.getLeftPoint().z();
922 m_hot_s0[iHit] = h.getsAmb(0);
923 m_hot_x1[iHit] = h.getRightPoint().x();
924 m_hot_y1[iHit] = h.getRightPoint().y();
925 m_hot_z1[iHit] = h.getRightPoint().z();
926 m_hot_s1[iHit] = h.getsAmb(1);
927 m_hot_drift[iHit] = h.getDriftDist();
928 m_hot_flag[iHit] = h.getSlayerType();
929 m_hot_deltaD[iHit]= h.getDeltaD();
930 m_hot_truth_x[iHit] = h.getXTruth();
931 m_hot_truth_y[iHit] = h.getYTruth();
932 m_hot_truth_z[iHit] = h.getZTruth();
933 m_hot_truth_drift[iHit] = h.getDriftDistTruth();
934 m_hot_truth_ambig[iHit] = h.getLrTruth();
935 }
936 if(m_hist)ntuple_hot->write();
937}
938void MdcHoughFinder::dumpHitOnTrack( RecMdcTrackCol* trackList_tds){
939 m_hot_run = m_run;
940 m_hot_evt = m_event;
941 RecMdcTrackCol::iterator iter = trackList_tds->begin();
942 for(;iter!=trackList_tds->end();iter++){
943 m_hot_trk = (*iter)->trackId();
944 m_hot_nhot = ((*iter)->getVecHits()).size()+(*iter)->getNcluster();
945
946 int iHit=0;
947 ClusterRefVec clusterRefVec = (*iter)->getVecClusters();
948 ClusterRefVec::iterator itCluster = clusterRefVec.begin();
949 for( ; itCluster != clusterRefVec.end(); itCluster++,iHit++){
950 int layer = (*itCluster)->getlayerid();
951 int wire = (*itCluster)->getsheetid();
952 m_hot_hitid[iHit] = (*itCluster)->getclusterid();
953 m_hot_layer[iHit] = layer;
954 m_hot_wire[iHit] = wire;
955 m_hot_x[iHit] = 0;
956 m_hot_y[iHit] = 0;
957 m_hot_z[iHit] = (*itCluster)->getRecZ();
958 m_hot_x0[iHit] = 0;
959 m_hot_y0[iHit] = 0;
960 m_hot_z0[iHit] = 0;
961 m_hot_s0[iHit] = 0;
962 m_hot_x1[iHit] = 0;
963 m_hot_y1[iHit] = 0;
964 m_hot_z1[iHit] = 0;
965 m_hot_s1[iHit] = 0;
966 m_hot_drift[iHit] = 0;
967 m_hot_flag[iHit] = (*itCluster)->getflag();
968 m_hot_deltaD[iHit]= 0;
969 m_hot_truth_x[iHit] = 0;
970 m_hot_truth_y[iHit] = 0;
971 m_hot_truth_z[iHit] = 0;
972 m_hot_truth_drift[iHit] = 0;
973 m_hot_truth_ambig[iHit] = 0;
974 }
975
976 HitRefVec vechits = (*iter)->getVecHits();
977 HitRefVec::iterator itHit = vechits.begin();
978 for(; itHit != vechits.end(); itHit++,iHit++){
979 const Identifier mdcid = (*itHit)->getMdcId();
980 int layer = MdcID::layer(mdcid);
981 int wire = MdcID::wire(mdcid);
982 m_hot_hitid[iHit] = (*itHit)->getId();
983 m_hot_layer[iHit] = layer;
984 m_hot_wire[iHit] = wire;
985 m_hot_x[iHit] = 0;
986 m_hot_y[iHit] = 0;
987 m_hot_z[iHit] = (*itHit)->getZhit();
988 m_hot_x0[iHit] = 0;
989 m_hot_y0[iHit] = 0;
990 m_hot_z0[iHit] = 0;
991 m_hot_s0[iHit] = 0;
992 m_hot_x1[iHit] = 0;
993 m_hot_y1[iHit] = 0;
994 m_hot_z1[iHit] = 0;
995 m_hot_s1[iHit] = 0;
996 m_hot_drift[iHit] = 0;
997 m_hot_flag[iHit] = (*itHit)->getStat();
998 m_hot_deltaD[iHit]= 0;
999 m_hot_truth_x[iHit] = 0;
1000 m_hot_truth_y[iHit] = 0;
1001 m_hot_truth_z[iHit] = 0;
1002 m_hot_truth_drift[iHit] = 0;
1003 m_hot_truth_ambig[iHit] = 0;
1004 }
1005 if(m_hist)ntuple_hot->write();
1006 }
1007}
1008void MdcHoughFinder::dumpHoughTrack(RecMdcTrackCol* trackList_tds){
1009 m_trk_run = m_run;
1010 m_trk_evt = m_event;
1011 m_trk_ntrk = trackList_tds->size();
1012 m_trk_size = trackList_tds->size();
1013 double alpha = -333.567;
1014 RecMdcTrackCol::iterator iter = trackList_tds->begin();
1015 for(int itrack=0;iter!=trackList_tds->end();iter++,itrack++){
1016 m_trk_trackId[itrack] = (*iter)->trackId() ;
1017 m_trk_charge[itrack] = (*iter)->charge() ;
1018 m_trk_dr[itrack] = (*iter)->helix(0) ;
1019 m_trk_phi0[itrack] = (*iter)->helix(1) ;
1020 m_trk_kappa[itrack] = (*iter)->helix(2) ;
1021 m_trk_dz[itrack] = (*iter)->helix(3) ;
1022 m_trk_tanl[itrack] = (*iter)->helix(4) ;
1023 m_trk_pxy[itrack] = (*iter)->pxy() ;
1024 m_trk_px[itrack] = (*iter)->px() ;
1025 m_trk_py[itrack] = (*iter)->py() ;
1026 m_trk_pz[itrack] = (*iter)->pz() ;
1027 m_trk_p[itrack] = (*iter)->p() ;
1028 m_trk_theta[itrack] = (*iter)->theta() ;
1029 m_trk_phi[itrack] = (*iter)->phi() ;
1030 m_trk_x[itrack] = (*iter)->x() ;
1031 m_trk_y[itrack] = (*iter)->y() ;
1032 m_trk_z[itrack] = (*iter)->z() ;
1033 m_trk_r[itrack] = (*iter)->r() ;
1034 m_trk_chi2[itrack] = (*iter)->chi2() ;
1035 m_trk_fiTerm[itrack] = (*iter)->getFiTerm() ;
1036 //m_trk_matchChi2[itrack] = (*iter)->getMatchChi2() ;
1037 m_trk_nhit[itrack] = (*iter)->getNhits() ;
1038 m_trk_ncluster[itrack] = (*iter)->getNcluster() ;
1039 m_trk_stat[itrack] = (*iter)->stat() ;
1040 m_trk_ndof[itrack] = (*iter)->ndof() ;
1041 m_trk_nster[itrack] = (*iter)-> nster() ;
1042 m_trk_nlayer[itrack] = (*iter)->nlayer() ;
1043 m_trk_firstLayer[itrack] = (*iter)->firstLayer() ;
1044 m_trk_lastLayer[itrack] = (*iter)->lastLayer() ;
1045 //m_trk_nCgemXClusters[itrack] = (*iter)->nCgemXCluster() ;
1046 //m_trk_nCgemVClusters[itrack] = (*iter)->nCgemVCluster() ;
1047 m_trk_nhop[itrack] = 0 ;
1048 m_trk_nhot[itrack] = 0 ;
1049 m_trk_Xc[itrack] = (*iter)->x() + ( (*iter)->helix(0) + alpha/(*iter)->helix(2) )*cos((*iter)->helix(1));
1050 m_trk_Yc[itrack] = (*iter)->y() + ( (*iter)->helix(0) + alpha/(*iter)->helix(2) )*sin((*iter)->helix(1));
1051 m_trk_R[itrack] = fabs(alpha/(*iter)->helix(2));
1052
1053 m_trk_truth_charge[itrack] = t_q;
1054 m_trk_truth_dr[itrack] = m_helix->dr();
1055 m_trk_truth_phi0[itrack] = m_helix->phi0();
1056 m_trk_truth_kappa[itrack] = m_helix->kappa();
1057 m_trk_truth_dz[itrack] = m_helix->dz();
1058 m_trk_truth_tanl[itrack] = m_helix->tanl();
1059 m_trk_truth_pxy[itrack] = m_helix->pt();
1060 m_trk_truth_px[itrack] = m_helix->momentum(0.).x();
1061 m_trk_truth_py[itrack] = m_helix->momentum(0.).y();
1062 m_trk_truth_pz[itrack] = m_helix->momentum(0.).z();
1063 m_trk_truth_p[itrack] = m_helix->momentum(0.).mag();
1064 m_trk_truth_theta[itrack] = acos(m_helix->momentum(0.).z()/m_helix->momentum(0.).mag());
1065 m_trk_truth_phi[itrack] = atan2(m_helix->momentum(0.).y(),m_helix->momentum(0.).x());
1066 m_trk_truth_x[itrack] = m_helix->pivot().x();
1067 m_trk_truth_y[itrack] = m_helix->pivot().y();
1068 m_trk_truth_z[itrack] = m_helix->pivot().z();
1069 m_trk_truth_r[itrack] = sqrt(m_helix->pivot().x()*m_helix->pivot().x()+m_helix->pivot().y()*m_helix->pivot().y());
1070 m_trk_truth_cosTheta[itrack] = m_helix->cosTheta();
1071 //m_trk_truth_Xc[itrack] = m_helix->center().x();
1072 //m_trk_truth_Yc[itrack] = m_helix->center().y() ;
1073 //m_trk_truth_R[itrack] = m_helix->radius();
1074 m_trk_truth_Xc[itrack] = m_helix->pivot().x() + ( m_helix->dr() + alpha/m_helix->kappa() )*cos(m_helix->phi0());
1075 m_trk_truth_Yc[itrack] = m_helix->pivot().y() + ( m_helix->dr() + alpha/m_helix->kappa() )*sin(m_helix->phi0());
1076 m_trk_truth_R[itrack] = fabs(alpha/m_helix->kappa());
1077 //cout<<(*iter)->helix(0)<<endl;
1078 //cout<<(*iter)->helix(1)<<endl;
1079 //cout<<(*iter)->helix(2)<<endl;
1080 //cout<<(*iter)->helix(3)<<endl;
1081 //cout<<(*iter)->helix(4)<<endl;
1082 //cout<<endl;
1083 }
1084 if(m_trk_ntrk==0){
1085 int itrack = 0;
1086 m_trk_size = 1;
1087 m_trk_truth_charge[itrack] = t_q;
1088 m_trk_truth_dr[itrack] = m_helix->dr();
1089 m_trk_truth_phi0[itrack] = m_helix->phi0();
1090 m_trk_truth_kappa[itrack] = m_helix->kappa();
1091 m_trk_truth_dz[itrack] = m_helix->dz();
1092 m_trk_truth_tanl[itrack] = m_helix->tanl();
1093 m_trk_truth_pxy[itrack] = m_helix->pt();
1094 m_trk_truth_px[itrack] = m_helix->momentum(0.).x();
1095 m_trk_truth_py[itrack] = m_helix->momentum(0.).y();
1096 m_trk_truth_pz[itrack] = m_helix->momentum(0.).z();
1097 m_trk_truth_p[itrack] = m_helix->momentum(0.).mag();
1098 m_trk_truth_theta[itrack] = acos(m_helix->momentum(0.).z()/m_helix->momentum(0.).mag());
1099 m_trk_truth_phi[itrack] = atan2(m_helix->momentum(0.).y(),m_helix->momentum(0.).x());
1100 m_trk_truth_x[itrack] = m_helix->pivot().x();
1101 m_trk_truth_y[itrack] = m_helix->pivot().y();
1102 m_trk_truth_z[itrack] = m_helix->pivot().z();
1103 m_trk_truth_r[itrack] = sqrt(m_helix->pivot().x()*m_helix->pivot().x()+m_helix->pivot().y()*m_helix->pivot().y());
1104 m_trk_truth_cosTheta[itrack] = m_helix->cosTheta();
1105 //m_trk_truth_Xc[itrack] = m_helix->center().x();
1106 //m_trk_truth_Yc[itrack] = m_helix->center().y() ;
1107 //m_trk_truth_R[itrack] = m_helix->radius();
1108 m_trk_truth_Xc[itrack] = m_helix->pivot().x() + ( m_helix->dr() + alpha/m_helix->kappa() )*cos(m_helix->phi0());
1109 m_trk_truth_Yc[itrack] = m_helix->pivot().y() + ( m_helix->dr() + alpha/m_helix->kappa() )*sin(m_helix->phi0());
1110 m_trk_truth_R[itrack] = fabs(alpha/m_helix->kappa());
1111 }
1112}
1113void MdcHoughFinder::dumpHoughTrack( HoughTrack& houghTrack, int itrack, int ntrack){
1114 double alpha = -333.567;
1115 HepVector barbar(5,0);
1116 double d0 = houghTrack.getD0();
1117 double phi0 = houghTrack.getPhi0();
1118 double omega = houghTrack.getOmega();
1119 double z0 = houghTrack.getZ0();
1120 double tanl = houghTrack.getTanl();
1121 barbar(1) = d0;
1122 barbar(2) = phi0;
1123 barbar(3) = omega;
1124 barbar(4) = z0;
1125 barbar(5) = tanl;
1126 HepVector bes = barbar2bes(barbar);
1127
1128 m_trk_run = m_run;
1129 m_trk_evt = m_event;
1130 m_trk_ntrk = ntrack;
1131 m_trk_size = ntrack;
1132 m_trk_trackId[itrack] = houghTrack.getTrkid();
1133 m_trk_charge[itrack] = houghTrack.getCharge();
1134 m_trk_dr[itrack] = bes(1);
1135 m_trk_phi0[itrack] = bes(2);
1136 m_trk_kappa[itrack] = bes(3);
1137 m_trk_dz[itrack] = bes(4);
1138 m_trk_tanl[itrack] = bes(5);
1139 m_trk_pxy[itrack] = houghTrack.getPt_least();
1140 m_trk_nhop[itrack] = houghTrack.getCenterPeak().peakHeight();
1141 m_trk_nhot[itrack] = houghTrack.getHitNumA(0);
1142 m_trk_Xc[itrack] = houghTrack.getCirX();
1143 m_trk_Yc[itrack] = houghTrack.getCirY();
1144 m_trk_R[itrack] = houghTrack.getCirR();
1145
1146 m_trk_truth_charge[itrack] = t_q;
1147 m_trk_truth_dr[itrack] = m_helix->dr();
1148 m_trk_truth_phi0[itrack] = m_helix->phi0();
1149 m_trk_truth_kappa[itrack] = m_helix->kappa();
1150 m_trk_truth_dz[itrack] = m_helix->dz();
1151 m_trk_truth_tanl[itrack] = m_helix->tanl();
1152 m_trk_truth_pxy[itrack] = m_helix->pt();
1153 m_trk_truth_px[itrack] = m_helix->momentum(0.).x();
1154 m_trk_truth_py[itrack] = m_helix->momentum(0.).y();
1155 m_trk_truth_pz[itrack] = m_helix->momentum(0.).z();
1156 m_trk_truth_p[itrack] = m_helix->momentum(0.).mag();
1157 m_trk_truth_theta[itrack] = acos(m_helix->momentum(0.).z()/m_helix->momentum(0.).mag());
1158 m_trk_truth_phi[itrack] = atan2(m_helix->momentum(0.).y(),m_helix->momentum(0.).x());
1159 m_trk_truth_x[itrack] = m_helix->pivot().x();
1160 m_trk_truth_y[itrack] = m_helix->pivot().y();
1161 m_trk_truth_z[itrack] = m_helix->pivot().z();
1162 m_trk_truth_r[itrack] = sqrt(m_helix->pivot().x()*m_helix->pivot().x()+m_helix->pivot().y()*m_helix->pivot().y());
1163 m_trk_truth_cosTheta[itrack] = m_helix->cosTheta();
1164 //m_trk_truth_Xc[itrack] = m_helix->center().x();
1165 //m_trk_truth_Yc[itrack] = m_helix->center().y() ;
1166 //m_trk_truth_R[itrack] = m_helix->radius();
1167 m_trk_truth_Xc[itrack] = m_helix->pivot().x() + ( m_helix->dr() + alpha/m_helix->kappa() )*cos(m_helix->phi0());
1168 m_trk_truth_Yc[itrack] = m_helix->pivot().y() + ( m_helix->dr() + alpha/m_helix->kappa() )*sin(m_helix->phi0());
1169 m_trk_truth_R[itrack] = fabs(alpha/m_helix->kappa());
1170 //}
1171}
1172HepVector barbar2bes(HepVector a)
1173{
1174 double dr = -a(1);
1175 double phi0 = a(2)-M_PI/2;
1176 while(phi0>2*M_PI)phi0-=2*M_PI;
1177 while(phi0<0)phi0+=2*M_PI;
1178 double kappa = a(3)*333.567;
1179 double dz = a(4);
1180 double tanl = a(5);
1181 HepVector bes(5,0);
1182 bes(1) = dr;
1183 bes(2) = phi0;
1184 bes(3) = kappa;
1185 bes(4) = dz;
1186 bes(5) = tanl;
1187 return bes;
1188}
1189HepVector bes2barbar(HepVector a)
1190{
1191 double d0 = -a(1);
1192 double phi0 = a(2)+M_PI/2;
1193 while(phi0> M_PI)phi0-=2*M_PI;
1194 while(phi0<-M_PI)phi0+=2*M_PI;
1195 double omega = a(3)/333.567;
1196 double z0 = a(4);
1197 double tanl = a(5);
1198 HepVector barbar(5,0);
1199 barbar(1) = d0;
1200 barbar(2) = phi0;
1201 barbar(3) = omega;
1202 barbar(4) = z0;
1203 barbar(5) = tanl;
1204 return barbar;
1205}
1206/*
1207void MdcHoughFinder::diffMap(const HoughMap& houghmap,const HoughMap& houghmap2){
1208 //map 1
1209 m_nMap1Pk=houghmap.getPeakNumber();
1210 for(int iPk=0;iPk< houghmap.getPeakNumber(); iPk++){
1211 m_PkRho1[iPk] = houghmap.getPeak(iPk).getRho();
1212 m_PkTheta1[iPk]= houghmap.getPeak(iPk).getTheta();
1213 }
1214 m_nMap1Tk=houghmap.getTrackNumber();
1215 for(int iTk=0;iTk< houghmap.getTrackNumber(); iTk++){
1216 m_TkRho1[iTk] = houghmap.getTrack(iTk).getRho();
1217 m_TkTheta1[iTk]= houghmap.getTrack(iTk).getTheta();
1218 }
1219 //map 2
1220 m_nMap2Pk=houghmap2.getPeakNumber();
1221 for(int iPk=0;iPk< houghmap2.getPeakNumber(); iPk++){
1222 m_PkRho2[iPk] = houghmap2.getPeak(iPk).getRho();
1223 m_PkTheta2[iPk]= houghmap2.getPeak(iPk).getTheta();
1224 }
1225 m_nMap2Tk=houghmap2.getTrackNumber();
1226 for(int iTk=0;iTk< houghmap2.getTrackNumber(); iTk++){
1227 m_TkRho2[iTk] = houghmap2.getTrack(iTk).getRho();
1228 m_TkTheta2[iTk]= houghmap2.getTrack(iTk).getTheta();
1229 }
1230}
1231
1232void MdcHoughFinder::Leastfit(vector<double> u,vector<double> v,double& k ,double& b){
1233 int N = u.size();
1234 if( N <= 2 ) return;
1235 double *x=new double[N];
1236 double *y=new double[N];
1237 for(int i=0;i<N;i++){
1238 x[i]=u[i];
1239 y[i]=v[i];
1240 }
1241
1242 TF1 *fpol1=new TF1("fpol1","pol1",-50,50);
1243 TGraph *tg=new TGraph(N,x,y);
1244 tg->Fit("fpol1","QN");
1245 double ktemp =fpol1->GetParameter(1);
1246 double btemp =fpol1->GetParameter(0);
1247 k = ktemp;
1248 b = btemp;
1249 delete []x;
1250 delete []y;
1251 delete fpol1;
1252 delete tg;
1253}
1254*/
1255
1256bool more_pt(const HoughTrack* tracka,const HoughTrack* trackb){
1257 return tracka->getPt3D() > trackb->getPt3D();
1258}
1259int MdcHoughFinder::storeTracks(RecMdcTrackCol*& trackList_tds ,RecMdcHitCol*& hitList_tds,vector<RecMdcTrack*>& vec_trackPatTds){
1260 MsgStream log(msgSvc(), name());
1261 StatusCode sc;
1262 // tds
1263 DataObject *aTrackCol;
1264 DataObject *aRecHitCol;
1265 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
1266 if(!m_combineTracking){
1267 eventSvc()->findObject("/Event/Recon/RecMdcTrackCol",aTrackCol);
1268 if(aTrackCol != NULL) {
1269 dataManSvc->clearSubTree("/Event/Recon/RecMdcTrackCol");
1270 eventSvc()->unregisterObject("/Event/Recon/RecMdcTrackCol");
1271 }
1272 eventSvc()->findObject("/Event/Recon/RecMdcHitCol",aRecHitCol);
1273 if(aRecHitCol != NULL) {
1274 dataManSvc->clearSubTree("/Event/Recon/RecMdcHitCol");
1275 eventSvc()->unregisterObject("/Event/Recon/RecMdcHitCol");
1276 }
1277 }
1278
1279 //RecMdcTrackCol* trackList_tds;
1280 eventSvc()->findObject("/Event/Recon/RecMdcTrackCol",aTrackCol);
1281 if (aTrackCol) {
1282 trackList_tds = dynamic_cast<RecMdcTrackCol*> (aTrackCol);
1283 }else{
1284 trackList_tds = new RecMdcTrackCol;
1285 StatusCode sc = eventSvc()->registerObject(EventModel::Recon::RecMdcTrackCol, trackList_tds);
1286 if(!sc.isSuccess()) {
1287 log << MSG::FATAL << " Could not register RecMdcTrack collection" <<endreq;
1288 return StatusCode::FAILURE;
1289 }
1290 }
1291 //RecMdcHitCol* hitList_tds;
1292 eventSvc()->findObject("/Event/Recon/RecMdcHitCol",aRecHitCol);
1293 if (aRecHitCol) {
1294 hitList_tds = dynamic_cast<RecMdcHitCol*> (aRecHitCol);
1295 }else{
1296 hitList_tds = new RecMdcHitCol;
1297 StatusCode sc = eventSvc()->registerObject(EventModel::Recon::RecMdcHitCol, hitList_tds);
1298 if(!sc.isSuccess()) {
1299 log << MSG::FATAL << " Could not register RecMdcHit collection" <<endreq;
1300 return StatusCode::FAILURE;
1301 }
1302 }
1303 //remove bad quality or low pt track(s)
1304 if(m_removeBadTrack && m_combineTracking) {
1305 if( m_debug>0 ) cout<<"PATTSF collect "<<trackList_tds->size()<<" track. "<<endl;
1306 if(trackList_tds->size()!=0){
1307 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1308 for(;iter_pat!=trackList_tds->end();iter_pat++){
1309 double d0=(*iter_pat)->helix(0);
1310 double kap = (*iter_pat)->helix(2);
1311 double pt = 0.00001;
1312 if(fabs(kap)>0.00001) pt = fabs(1./kap);
1313 double dz=(*iter_pat)->helix(3);
1314 double chi2=(*iter_pat)->chi2();
1315 if( m_debug>0) cout<<"d0: "<<d0<<" z0: "<<dz<<" pt "<<pt<<" chi2 "<<chi2<<endl;
1316 //if( (fabs(d0)>m_dropTrkDrCut || fabs(dz)>m_dropTrkDzCut || chi2>m_dropTrkChi2Cut) && pt<=m_dropTrkPtCut)
1317 if( pt<=m_dropTrkPtCut ){
1318 vec_trackPatTds.push_back(*iter_pat);
1319 //remove hits on track
1320 HitRefVec rechits = (*iter_pat)->getVecHits();
1321 HitRefVec::iterator hotIter = rechits.begin();
1322 while (hotIter!=rechits.end()) {
1323 Identifier id = (*hotIter)->getMdcId();
1324 int layer = MdcID::layer(id);
1325 int wire = MdcID::wire(id);
1326 if(m_debug>0) cout <<"remove hit " << (*hotIter)->getId()<<"("<<layer<<","<<wire<<")"<<endl;
1327 hitList_tds->remove(*hotIter);
1328 hotIter++;
1329 }
1330 //if( (fabs(d0)>3*m_dropTrkDrCut || fabs(dz)>3*m_dropTrkDzCut) ){ // drop pattsf fate track
1331 // trackList_tds->remove(*iter_pat);
1332 // iter_pat--;
1333 //}
1334 }
1335 if( m_debug>0 ) cout<<"after delete trackcol size : "<<trackList_tds->size()<<endl;
1336 }
1337 } else {
1338 if(m_debug>0) cout<<" PATTSF find 0 track. "<<endl;
1339 }
1340 }//end of remove bad quality high pt track
1341
1342 int nTdsTk=trackList_tds->size();
1343 return nTdsTk;
1344}//end of stroeTracks
1345
1346void MdcHoughFinder::clearMem(MdcTrackList& list1,MdcTrackList& list2){
1347 cout<<"length in clearMem "<<list1.length()<<" "<<list2.length()<<endl;
1348 cout<<"in list "<<vectrk_for_clean.size()<<endl;
1349
1350 for(unsigned int i=0;i<vectrk_for_clean.size();i++){
1351 int sametrk=0;
1352 for(unsigned int j=0;j<list1.length();j++){
1353 cout<<"-i j "<<i<<" "<<j<<" "<<vectrk_for_clean[i]<<" "<<&(list1[j]->track())<<endl;
1354 if(vectrk_for_clean[i] == &(list1[j]->track()) ) {sametrk=1;cout<<"not delete new trk "<<endl;}
1355 //delete list1[j];
1356 }
1357 for(unsigned int k=0;k<list2.length();k++){
1358 cout<<"+i k "<<i<<" "<<k<<" "<<vectrk_for_clean[i]<<" "<<&(list2[k]->track())<<endl;
1359 if(vectrk_for_clean[i] == &(list2[k]->track()) ) {sametrk=1;cout<<"not delete new trk "<<endl;}
1360 //delete list2[k];
1361 }
1362 if( sametrk ==0 ) {
1363 cout<<"delete i "<<i<<endl;
1364 delete vectrk_for_clean[i];
1365 vectrk_for_clean[i] = NULL;
1366 }
1367 }
1368 vectrk_for_clean.clear();
1369}
1370
1371int MdcHoughFinder::judgeChargeTrack(MdcTrackList& list1 ,MdcTrackList& list2){
1372 if(m_debug>0) cout<<"in judgeChargeTrack"<<endl;
1373 if(m_debug>0) cout<<"ntrack length neg : "<<list1.length()<<endl;
1374 if(m_debug>0) cout<<"ntrack length pos : "<<list2.length()<<endl;
1375 double R_cut = 81.0;//radius of MDC
1376 for(int itrack1=0; itrack1<list1.nTrack(); itrack1++){
1377 MdcTrack* track_1 = list1[itrack1];
1378 TrkExchangePar par1 = track_1->track().fitResult()->helix(0.);
1379 double d0_1 = par1.d0();
1380 double phi0_1 = par1.phi0();
1381 double omega_1 = par1.omega();
1382 double cr=fabs(1./par1.omega());
1383 double cx= sin(par1.phi0()) *(par1.d0()+1/par1.omega()) * -1.; //z axis verse,x_babar = -x_belle
1384 double cy= -1.*cos(par1.phi0()) *(par1.d0()+1/par1.omega()) * -1;//???
1385 double z0_1 = par1.z0();
1386 if(d0_1+2.0*cr>R_cut)continue;
1387 for(int itrack2=0; itrack2<list2.nTrack(); itrack2++){
1388 MdcTrack* track_2 = list2[itrack2];
1389 TrkExchangePar par2 = track_2->track().fitResult()->helix(0.);
1390 double d0_2 = par2.d0();
1391 double phi0_2 = par2.phi0();
1392 double omega_2 = par2.omega();
1393 double cR=fabs(1./par2.omega());
1394 double cX= sin(par2.phi0()) *(par2.d0()+1/par2.omega()) * -1.; //z axis verse,x_babar = -x_belle
1395 double cY= -1.*cos(par2.phi0()) *(par2.d0()+1/par2.omega()) * -1;//???
1396 double z0_2= par2.z0();
1397 if(d0_2+2.0*cR>R_cut)continue;
1398 double bestDiff = 1.0e+20;
1399 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1400 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1401 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1402 if(diff < bestDiff){
1403 bestDiff = diff;
1404 }
1405 }
1406 }
1407
1408 if(bestDiff != 1.0e20) {
1409 if(m_debug>0) {
1410 cout<<"There is ambiguous +- charge in the track list "<<endl;
1411 cout<<"z0_1 : "<<z0_1<<" z0_2 : "<<z0_2<<endl;
1412 }
1413 //iter_hough2 = vec_track.erase(iter_hough2); iter_hough2--;
1414 if( fabs(z0_1) >= fabs(z0_2) ){
1415 //cout<<"remove track:"<<track_1->track().id()<<" "<<(track_1->track().fitResult()->pt())*(track_1->track().fitResult()->charge())<<endl;
1416 list1.remove( track_1 );
1417 itrack1--;
1418 break;
1419 }
1420 if( fabs(z0_1) < fabs(z0_2) ){
1421 //cout<<"remove track:"<<track_2->track().id()<<" "<<(track_2->track().fitResult()->pt())*(track_2->track().fitResult()->charge())<<endl;
1422 list2.remove( track_2 );
1423 itrack2--;
1424 break;
1425 }
1426 }
1427 if(bestDiff == 1.0e20) { if(m_debug>0) cout<<" no (+-) track in hough"<<endl; }
1428 }
1429 }
1430}
1431
1432void MdcHoughFinder::compareHough(MdcTrackList& mdcTrackList){
1433 if(m_debug>0) cout<<"in compareHough "<<endl;
1434 if(m_debug>0) cout<<"ntrack : "<<mdcTrackList.length()<<endl;
1435 for(int itrack=0; itrack<mdcTrackList.length(); itrack++){
1436 MdcTrack* track = mdcTrackList[itrack];
1437 TrkExchangePar par = track->track().fitResult()->helix(0.);
1438 int nhit = track->track().hots()->nHit();
1439 double pt = (1./par.omega())/333.567;
1440 if(m_debug>0) cout<<"i Track : "<<itrack<<" nHit: "<<nhit<<" pt: "<<pt<<endl;
1441 }
1442 // vector<HoughTrack>::iterator iter_hough = vec_track.begin();
1443 // vector<HoughTrack>::iterator iter_hough2 = vec_track.begin()+1;
1444 for(int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1445 MdcTrack* track_1 = mdcTrackList[itrack1];
1446 TrkExchangePar par1 = track_1->track().fitResult()->helix(0.);
1447 int nhit1 = track_1->track().hots()->nHit();
1448 double d0_1 = par1.d0();
1449 double phi0_1 = par1.phi0();
1450 double omega_1 = par1.omega();
1451 double z0_1= par1.z0();
1452 double cr=fabs(1./par1.omega());
1453 double cx= sin(par1.phi0()) *(par1.d0()+1/par1.omega()) * -1.; //z axis verse,x_babar = -x_belle
1454 double cy= -1.*cos(par1.phi0()) *(par1.d0()+1/par1.omega()) * -1;//???
1455 if(m_debug>0) cout<<"circle 1 : "<<cr<<","<<cx<<","<<cy<<endl;
1456
1457 for(int itrack2=itrack1+1; itrack2<mdcTrackList.length(); itrack2++){
1458 MdcTrack* track_2 = mdcTrackList[itrack2];
1459 TrkExchangePar par2 = track_2->track().fitResult()->helix(0.);
1460 int nhit2 = track_2->track().hots()->nHit();
1461 double d0_2 = par2.d0();
1462 double phi0_2 = par2.phi0();
1463 double omega_2 = par2.omega();
1464 double z0_2= par2.z0();
1465 double cR=fabs(1./par2.omega());
1466 double cX= sin(par2.phi0()) *(par2.d0()+1/par2.omega()) * -1.; //z axis verse,x_babar = -x_belle
1467 double cY= -1.*cos(par2.phi0()) *(par2.d0()+1/par2.omega()) * -1;//???
1468 if(m_debug>0) cout<<"circle 2 : "<<cR<<","<<cX<<","<<cY<<endl;
1469
1470 double bestDiff = 1.0e+20;
1471 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1472 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1473 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1474 if(diff < bestDiff){
1475 bestDiff = diff;
1476 }
1477 }
1478 }
1479
1480 double zdiff = z0_1-z0_2;
1481 if(bestDiff != 1.0e20 && fabs(zdiff)<25.){
1482 if(m_debug>0) cout<<"z0_1 : "<<z0_1<<" z0_2 : "<<z0_2<<endl;
1483 //if( fabs(z0_1)>fabs(z0_2) && fabs(z0_1)>m_z0Cut_compareHough)
1484 if( nhit1<nhit2 && (fabs(z0_1)>fabs(z0_2) && fabs(z0_1)>m_z0Cut_compareHough) ){ //FIXME
1485 if(m_debug>0) cout<<"remove track1 "<<1./par1.omega()/333.567<<endl;
1486 //remove 1
1487 mdcTrackList.remove( track_1 );
1488 itrack1--;
1489 break;
1490 }
1491 else{
1492 //remove 2
1493 if(m_debug>0) cout<<"remove track2 "<<1./par2.omega()/333.567<<endl;
1494 //remove 1
1495 mdcTrackList.remove( track_2 );
1496 itrack2--;
1497 }
1498 }
1499 if(bestDiff == 1.0e20) { if(m_debug>0) cout<<" no same track in hough"<<endl; }
1500 }
1501 }
1502}
1503int MdcHoughFinder::comparePatTsf(MdcTrackList& mdcTrackList, RecMdcTrackCol* trackList_tds){
1504 // vector<HoughTrack>::iterator iter_hough = vec_track.begin();
1505 // int itrk_hough=0;
1506 // for(;iter_hough != vec_track.end();iter_hough++)
1507 // if(m_debug>0) cout<<"being hough trk "<<itrk_hough<<endl;
1508 // itrk_hough++;
1509 // double cr= (*iter_hough).getCirR();
1510 // double cx= (*iter_hough).getCirX();
1511 // double cy= (*iter_hough).getCirY();
1512 for(int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1513 MdcTrack* track_1 = mdcTrackList[itrack1];
1514 TrkExchangePar par1 = track_1->track().fitResult()->helix(0.);
1515 int nhit1 = track_1->track().hots()->nHit();
1516 double d0_1 = par1.d0();
1517 double phi0_1 = par1.phi0();
1518 double omega_1 = par1.omega();
1519 double z0_1= par1.z0();
1520 double cr=fabs(1./par1.omega());
1521 double cx= sin(par1.phi0()) *(par1.d0()+1/par1.omega()) * -1.; //z axis verse,x_babar = -x_belle
1522 double cy= -1.*cos(par1.phi0()) *(par1.d0()+1/par1.omega()) * -1;//???
1523
1524 //track2
1525 double bestDiff = 1.0e+20;
1526 double ptDiff = 0.0;
1527 double cR, cX, cY;
1528 vector<double> a0,a1,a2,a3,a4;
1529 RecMdcTrackCol::iterator iterBest;
1530 RecMdcTrackCol::iterator iteritrk = trackList_tds->begin();
1531 int itrk=0;
1532 for(;iteritrk!=trackList_tds->end();iteritrk++){
1533 if(m_debug>0) cout<<"being pattsf trk "<<itrk<<endl;
1534 double pt=(*iteritrk)->pxy();
1535 a0.push_back( (*iteritrk)->helix(0) );
1536 a1.push_back( (*iteritrk)->helix(1) );
1537 a2.push_back( (*iteritrk)->helix(2) );
1538 a3.push_back( (*iteritrk)->helix(3) );
1539 a4.push_back( (*iteritrk)->helix(4) );
1540 cR=(-333.567)/a2[itrk];
1541 cX=(cR+a0[itrk])*cos(a1[itrk]);
1542 cY=(cR+a0[itrk])*sin(a1[itrk]);
1543 if(m_debug>0)
1544 {
1545 cout<<" compare PATTSF and HOUGH "<<endl;
1546 cout<<" fabs(cX) "<< fabs(cX)<< "fabs(cx) "<<fabs(cx)<<endl;
1547 cout<<" fabs(cY) "<< fabs(cY)<< "fabs(cy) "<<fabs(cy)<<endl;
1548 cout<<" fabs(cR) "<< fabs(cR)<< "fabs(cr) "<<fabs(cr)<<endl;
1549 cout<<" fabs(cx-cX) "<< fabs(cx-cX)<< "fabs(cy-cY) "<<fabs(cy-cY)<<" fabs(cr-cR) "<< fabs(cr-cR)<<endl;
1550 }
1551
1552 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1553 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1554 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1555 if(m_debug>0) cout<<" diff "<<diff<<" pt "<<pt<<endl;
1556 if( fabs(pt) > ptDiff){
1557 ptDiff= pt;
1558 iterBest=iteritrk;
1559 bestDiff = diff;
1560 }
1561 //if(diff < bestDiff){
1562 // bestDiff = diff;
1563 // // bestIndex = itrk;
1564 // iterBest=iteritrk;
1565 //}
1566 }
1567 }
1568 itrk++;
1569 }
1570 if(bestDiff != 1.0e20) {
1571 if(m_debug>0) cout<<" same track pattsf & hough , then compare nhit. "<<endl;
1572 double d0_pattsf =(*iterBest)->helix(0);
1573 double z0_pattsf =(*iterBest)->helix(3);
1574 double d0_hough = d0_1;
1575 double z0_hough = z0_1;
1576 int use_pattsf(1),use_hough(1);
1577 if( fabs(d0_pattsf)>m_dropTrkDrCut || fabs(z0_pattsf)>m_dropTrkDzCut ) use_pattsf=0;
1578 if( fabs(d0_hough)>m_dropTrkDrCut || fabs(z0_hough)>m_dropTrkDzCut ) use_hough=0;
1579 if( use_pattsf==0 && use_hough==1 ) {
1580 trackList_tds->remove(*iterBest);
1581 if(m_debug>0) cout<<" use houghTrack, vertex pattsf wrong"<<endl;
1582 }
1583 if( use_pattsf==1 && use_hough==0 ) {
1584 mdcTrackList.remove( track_1 );
1585 itrack1--;
1586 if(m_debug>0) cout<<" use pattsfTrack, vertex hough wrong"<<endl;
1587 }
1588 if( (use_pattsf==0 && use_hough==0) || (use_pattsf==1 && use_hough==1) ){
1589 int nhit_pattsf=( (*iterBest)->ndof()+5 );
1590 int nhit_hough = nhit1;
1591 if(m_debug>0) cout<<" nhit "<<nhit_pattsf<<" "<<nhit_hough<<endl;
1592 if( nhit_pattsf>nhit_hough ) {
1593 mdcTrackList.remove( track_1 );
1594 itrack1--;
1595 if(m_debug>0) cout<<" use pattsfTrack "<<endl;
1596 }
1597 else{
1598 trackList_tds->remove(*iterBest);
1599 if(m_debug>0) cout<<" use houghTrack "<<endl;
1600 }
1601 }
1602 }
1603 // if(m_debug>0) cout<<" d0"<<d0_pattsf<<" "<<d0_hough<<endl;
1604 // if(m_debug>0) cout<<" z0"<<z0_pattsf<<" "<<z0_hough<<endl;
1605 // if( fabs(d0_pattsf) >= fabs(d0_hough) && fabs(z0_pattsf) >= fabs(z0_hough) ) {
1606 // trackList_tds->remove(*iterBest);
1607 // if(m_debug>0) cout<<" use houghTrack "<<endl;
1608 // }
1609 // else{
1610 // iter_hough = vec_track.erase(iter_hough); iter_hough--;
1611 // if(m_debug>0) cout<<" use pattsfTrack "<<endl;
1612 // }
1613
1614 if(bestDiff == 1.0e20) { if(m_debug>0) cout<<" no same track in pattsf"<<endl; }
1615 //if(bestDiff != 1.0e20) { iter_hough = vec_track.erase(iter_hough); iter_hough--;}
1616 //if(bestDiff == 1.0e20) { if(m_debug>0) cout<<" no merge "<<endl; }
1617 }
1618 //cout<<"size after combine "<<trackList_tds->size()<<endl;
1619 if(trackList_tds->size()!=0){
1620 int digi=0;
1621 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1622 for(;iter_pat!=trackList_tds->end();iter_pat++,digi++){
1623 (*iter_pat)->setTrackId(digi);
1624 // cout<<"digi "<<(*iter_pat)->trackId()<<endl;
1625 }
1626 }
1627 return trackList_tds->size();
1628}
1629//int MdcHoughFinder::judgeHit(MdcTrackList& list,const vector<HoughTrack>& trackCol)
1630int MdcHoughFinder::judgeHit(MdcTrackList& list,vector<MdcTrack*>& trackCol){
1631 if(m_debug>0) cout<<"in judgHit: "<<endl;
1632 for( unsigned int i =0;i<trackCol.size();i++){
1633 //MdcTrack *mdcTrack = new MdcTrack(trackCol[i].getTrk());
1634 //list.append(mdcTrack);
1635 list.append(trackCol[i]);
1636 }
1637 if(m_cgem || m_skipMDCIT)list.setNoInner(true);
1638 int nDeleted(0);
1639 //nDeleted = list.
1640 return nDeleted;
1641}
1642bool sortCluster(const RecCgemCluster* clusterA , const RecCgemCluster* clusterB){
1643 return clusterA->getlayerid()<clusterB->getlayerid();
1644}
1645int MdcHoughFinder::storeTracks(RecMdcTrackCol* trackList, RecMdcHitCol* hitList, HoughTrackList& houghTrackList){
1646
1647 int tracklist_size = houghTrackList.getTrackNum();
1648 for(int itrack=0;itrack<tracklist_size;itrack++){
1649 HoughTrack &houghTrack = houghTrackList.getTrack(itrack);
1650 RecMdcTrack* recMdcTrack = new RecMdcTrack();
1651 recHitCol recHitVec = houghTrack.getHoughHitList();
1652 int hitId = 0;
1653 int nSt=0;
1654 int nHits = recHitVec.size();
1655 int tkStat = 4;
1656 int q = houghTrack.getCharge();
1657 double phi0 = houghTrack.getPhi0();
1658 double tanDip = houghTrack.getTanl();
1659 double d0 = houghTrack.getD0();
1660 //momenta and position
1661 double helixPar[5];
1662 helixPar[0] = -d0;
1663 double tphi0 = phi0 - Constants::pi/2.;
1664 if (tphi0 < 0. ) tphi0 += Constants::pi * 2.;
1665 helixPar[1] = tphi0;
1666 helixPar[2] = houghTrack.getOmega()*333.567;
1667 helixPar[3] = houghTrack.getZ0();
1668 helixPar[4] = tanDip;
1669 recMdcTrack->setTrackId(itrack);
1670 recMdcTrack->setHelix(helixPar);
1671 recMdcTrack->setCharge(q);
1672 recMdcTrack->setStat(tkStat);
1673 recMdcTrack->setNhits(nHits);
1674 //-----------hit list-------------
1675 HitRefVec hitRefVec;
1676 ClusterRefVec clusterRefVec;
1677 for (int i=0;i<nHits;i++){
1678 if(recHitVec[i].getflag()!=0 ) continue;
1679 if(recHitVec[i].getDetectorType()==MDC){
1680 RecMdcHit* recMdcHit = new RecMdcHit;
1681 Identifier mdcId = recHitVec[i].digi()->identify();
1682 recMdcHit->setMdcId(mdcId);
1683 double fltLen = recHitVec[i].getRet().second/(1./sqrt(1+tanDip*tanDip));
1684 //fltLen = recHitVec[i].getRet().second;
1685 recMdcHit->setFltLen(fltLen);
1686 recMdcHit->setTdc(recHitVec[i].digi()->getTimeChannel());
1687 recMdcHit->setAdc(recHitVec[i].digi()->getChargeChannel());
1688 if(recHitVec[i].getDetectorType()!=0)nSt++;
1689 hitList->push_back(recMdcHit);
1690 SmartRef<RecMdcHit> refHit(recMdcHit);
1691 hitRefVec.push_back(refHit);
1692 }else if(recHitVec[i].getDetectorType()==CGEM && recHitVec[i].getSlayerType()==2){
1693 clusterRefVec.push_back(recHitVec[i].getCluster());
1694 }
1695 }
1696 std::sort(clusterRefVec.begin(),clusterRefVec.end(),sortCluster);
1697 recMdcTrack->setNster(nSt);
1698 recMdcTrack->setVecHits(hitRefVec);
1699 recMdcTrack->setVecClusters(clusterRefVec);
1700 recMdcTrack->setNcluster(clusterRefVec.size());
1701 trackList->push_back(recMdcTrack);
1702 //cout<<helixPar[2]<<endl;
1703 }
1704}//end of storeTrack
1705
1706void MdcHoughFinder::printTrack(vector<MdcTrack*> vec_MdcTrack)
1707{
1708 //cout<<"track number: "<<vec_MdcTrack.length()<<endl;
1709 for( unsigned int i =0;i<vec_MdcTrack.size();i++){
1710 cout<<"trackID:"<<vec_MdcTrack[i]->track().id()<<" ";
1711 vec_MdcTrack[i]->track().printAll(cout);
1712 //<<(vec_MdcTrack[i]->track().fitResult()->pt())*(vec_MdcTrack[i]->track().fitResult()->charge())<<endl;
1713 }
1714 //cout<<endl;
1715}
1716void MdcHoughFinder::printTrack(MdcTrackList& mdcTrackList)
1717{
1718 //cout<<"track number: "<<mdcTrackList.length()<<endl;
1719 for( unsigned int i =0;i<mdcTrackList.length();i++){
1720 cout<<"trackID:"<<mdcTrackList[i]->track().id()<<" "
1721 <<(mdcTrackList[i]->track().fitResult()->pt())*(mdcTrackList[i]->track().fitResult()->charge())<<endl;
1722 mdcTrackList[i]->track().printAll(cout);
1723 }
1724 //cout<<endl;
1725}
1726
1728 MsgStream log(msgSvc(), name());
1729
1730 NTuplePtr nt1(ntupleSvc(), "mdcHoughFinder/hit");
1731 if ( nt1 ){
1732 ntuple_hit= nt1;
1733 } else {
1734 ntuple_hit= ntupleSvc()->book("mdcHoughFinder/hit", CLID_ColumnWiseTuple, "hit");
1735 if(ntuple_hit){
1736 ntuple_hit->addItem("hit_run", m_hit_run);
1737 ntuple_hit->addItem("hit_evt", m_hit_evt);
1738 ntuple_hit->addItem("hit_nhit", m_hit_nhit, 0, 10000);
1739 ntuple_hit->addItem("hit_hitid", m_hit_nhit, m_hit_hitid);
1740 ntuple_hit->addItem("hit_layer", m_hit_nhit, m_hit_layer);
1741 ntuple_hit->addItem("hit_wire", m_hit_nhit, m_hit_wire);
1742 ntuple_hit->addItem("hit_x", m_hit_nhit, m_hit_x);
1743 ntuple_hit->addItem("hit_y", m_hit_nhit, m_hit_y);
1744 ntuple_hit->addItem("hit_z", m_hit_nhit, m_hit_z);
1745 ntuple_hit->addItem("hit_driftdist", m_hit_nhit, m_hit_driftdist);
1746 ntuple_hit->addItem("hit_drifttime", m_hit_nhit, m_hit_drifttime);
1747 ntuple_hit->addItem("hit_flag", m_hit_nhit, m_hit_flag);
1748 ntuple_hit->addItem("hit_truth_x", m_hit_nhit, m_hit_truth_x);
1749 ntuple_hit->addItem("hit_truth_y", m_hit_nhit, m_hit_truth_y);
1750 ntuple_hit->addItem("hit_truth_z", m_hit_nhit, m_hit_truth_z);
1751 ntuple_hit->addItem("hit_truth_drift", m_hit_nhit, m_hit_truth_drift);
1752 ntuple_hit->addItem("hit_truth_ambig", m_hit_nhit, m_hit_truth_ambig);
1753 } else { log << MSG::ERROR << "Cannot book tuple mdcHoughFinder/hit" <<endmsg;
1754 return StatusCode::FAILURE;
1755 }
1756 }
1757
1758 NTuplePtr nt2(ntupleSvc(), "mdcHoughFinder/hot");
1759 if ( nt2 ){
1760 ntuple_hot = nt2;
1761 } else {
1762 ntuple_hot = ntupleSvc()->book("mdcHoughFinder/hot", CLID_ColumnWiseTuple, "hot");
1763 if(ntuple_hot){
1764 ntuple_hot->addItem("hot_run", m_hot_run);
1765 ntuple_hot->addItem("hot_evt", m_hot_evt);
1766 ntuple_hot->addItem("hot_trk", m_hot_trk);
1767 ntuple_hot->addItem("hot_nhot", m_hot_nhot, 0, 1000 );
1768 ntuple_hot->addItem("hot_hitid", m_hot_nhot, m_hot_hitid);
1769 ntuple_hot->addItem("hot_layer", m_hot_nhot, m_hot_layer);
1770 ntuple_hot->addItem("hot_wire", m_hot_nhot, m_hot_wire);
1771 ntuple_hot->addItem("hot_x", m_hot_nhot, m_hot_x);
1772 ntuple_hot->addItem("hot_y", m_hot_nhot, m_hot_y);
1773 ntuple_hot->addItem("hot_z", m_hot_nhot, m_hot_z);
1774 ntuple_hot->addItem("hot_x0", m_hot_nhot, m_hot_x0);
1775 ntuple_hot->addItem("hot_y0", m_hot_nhot, m_hot_y0);
1776 ntuple_hot->addItem("hot_z0", m_hot_nhot, m_hot_z0);
1777 ntuple_hot->addItem("hot_s0", m_hot_nhot, m_hot_s0);
1778 ntuple_hot->addItem("hot_x1", m_hot_nhot, m_hot_x1);
1779 ntuple_hot->addItem("hot_y1", m_hot_nhot, m_hot_y1);
1780 ntuple_hot->addItem("hot_z1", m_hot_nhot, m_hot_z1);
1781 ntuple_hot->addItem("hot_s1", m_hot_nhot, m_hot_s1);
1782 ntuple_hot->addItem("hot_drift", m_hot_nhot, m_hot_drift);
1783 ntuple_hot->addItem("hot_flag", m_hot_nhot, m_hot_flag);
1784 ntuple_hot->addItem("hot_deltaD", m_hot_nhot, m_hot_deltaD);
1785 ntuple_hot->addItem("hot_truth_x", m_hot_nhot, m_hot_truth_x);
1786 ntuple_hot->addItem("hot_truth_y", m_hot_nhot, m_hot_truth_y);
1787 ntuple_hot->addItem("hot_truth_z", m_hot_nhot, m_hot_truth_z);
1788 ntuple_hot->addItem("hot_truth_drift", m_hot_nhot, m_hot_truth_drift);
1789 ntuple_hot->addItem("hot_truth_ambig", m_hot_nhot, m_hot_truth_ambig);
1790
1791 } else { log << MSG::ERROR << "Cannot book tuple mdcHoughFinder/hot" <<endmsg;
1792 return StatusCode::FAILURE;
1793 }
1794 }
1795
1796 NTuplePtr nt3(ntupleSvc(), "mdcHoughFinder/trk");
1797 if ( nt3 ){
1798 ntuple_trk = nt3;
1799 } else {
1800 ntuple_trk = ntupleSvc()->book("mdcHoughFinder/trk", CLID_ColumnWiseTuple, "trk");
1801 if(ntuple_trk){
1802 ntuple_trk->addItem("trk_run", m_trk_run);
1803 ntuple_trk->addItem("trk_evt", m_trk_evt);
1804 ntuple_trk->addItem("trk_ntrk", m_trk_ntrk);
1805 ntuple_trk->addItem("trk_size", m_trk_size, 0, 100);
1806 ntuple_trk->addItem("trk_trackId", m_trk_size, m_trk_trackId);
1807 ntuple_trk->addItem("trk_charge", m_trk_size, m_trk_charge);
1808 ntuple_trk->addItem("trk_dr", m_trk_size, m_trk_dr);
1809 ntuple_trk->addItem("trk_phi0", m_trk_size, m_trk_phi0);
1810 ntuple_trk->addItem("trk_kappa", m_trk_size, m_trk_kappa);
1811 ntuple_trk->addItem("trk_dz", m_trk_size, m_trk_dz);
1812 ntuple_trk->addItem("trk_tanl", m_trk_size, m_trk_tanl);
1813 ntuple_trk->addItem("trk_pxy", m_trk_size, m_trk_pxy);
1814 ntuple_trk->addItem("trk_px", m_trk_size, m_trk_px);
1815 ntuple_trk->addItem("trk_py", m_trk_size, m_trk_py);
1816 ntuple_trk->addItem("trk_pz", m_trk_size, m_trk_pz);
1817 ntuple_trk->addItem("trk_p", m_trk_size, m_trk_p);
1818 ntuple_trk->addItem("trk_theta", m_trk_size, m_trk_theta);
1819 ntuple_trk->addItem("trk_phi", m_trk_size, m_trk_phi);
1820 ntuple_trk->addItem("trk_x", m_trk_size, m_trk_x);
1821 ntuple_trk->addItem("trk_y", m_trk_size, m_trk_y);
1822 ntuple_trk->addItem("trk_z", m_trk_size, m_trk_z);
1823 ntuple_trk->addItem("trk_r", m_trk_size, m_trk_r);
1824 ntuple_trk->addItem("trk_chi2", m_trk_size, m_trk_chi2);
1825 ntuple_trk->addItem("trk_fiTerm", m_trk_size, m_trk_fiTerm);
1826 ntuple_trk->addItem("trk_matchChi2", m_trk_size, m_trk_matchChi2);
1827 ntuple_trk->addItem("trk_nhit", m_trk_size, m_trk_nhit);
1828 ntuple_trk->addItem("trk_ncluster", m_trk_size, m_trk_ncluster);
1829 ntuple_trk->addItem("trk_stat", m_trk_size, m_trk_stat);
1830 ntuple_trk->addItem("trk_ndof", m_trk_size, m_trk_ndof);
1831 ntuple_trk->addItem("trk_nster", m_trk_size, m_trk_nster);
1832 ntuple_trk->addItem("trk_nlayer", m_trk_size, m_trk_nlayer);
1833 ntuple_trk->addItem("trk_firstLayer", m_trk_size, m_trk_firstLayer);
1834 ntuple_trk->addItem("trk_lastLayer", m_trk_size, m_trk_lastLayer);
1835 ntuple_trk->addItem("trk_nCgemXClusters", m_trk_size, m_trk_nCgemXClusters);
1836 ntuple_trk->addItem("trk_nCgemVClusters", m_trk_size, m_trk_nCgemVClusters);
1837 ntuple_trk->addItem("trk_nhop", m_trk_size, m_trk_nhop);
1838 ntuple_trk->addItem("trk_nhot", m_trk_size, m_trk_nhot);
1839 ntuple_trk->addItem("trk_Xc", m_trk_size, m_trk_Xc);
1840 ntuple_trk->addItem("trk_Yc", m_trk_size, m_trk_Yc);
1841 ntuple_trk->addItem("trk_R", m_trk_size, m_trk_R);
1842
1843 ntuple_trk->addItem("trk_truth_charge", m_trk_size, m_trk_truth_charge);
1844 ntuple_trk->addItem("trk_truth_dr", m_trk_size, m_trk_truth_dr);
1845 ntuple_trk->addItem("trk_truth_phi0", m_trk_size, m_trk_truth_phi0);
1846 ntuple_trk->addItem("trk_truth_kappa", m_trk_size, m_trk_truth_kappa);
1847 ntuple_trk->addItem("trk_truth_dz", m_trk_size, m_trk_truth_dz);
1848 ntuple_trk->addItem("trk_truth_tanl", m_trk_size, m_trk_truth_tanl);
1849 ntuple_trk->addItem("trk_truth_pxy", m_trk_size, m_trk_truth_pxy);
1850 ntuple_trk->addItem("trk_truth_px", m_trk_size, m_trk_truth_px);
1851 ntuple_trk->addItem("trk_truth_py", m_trk_size, m_trk_truth_py);
1852 ntuple_trk->addItem("trk_truth_pz", m_trk_size, m_trk_truth_pz);
1853 ntuple_trk->addItem("trk_truth_p", m_trk_size, m_trk_truth_p);
1854 ntuple_trk->addItem("trk_truth_theta", m_trk_size, m_trk_truth_theta);
1855 ntuple_trk->addItem("trk_truth_phi", m_trk_size, m_trk_truth_phi);
1856 ntuple_trk->addItem("trk_truth_x", m_trk_size, m_trk_truth_x);
1857 ntuple_trk->addItem("trk_truth_y", m_trk_size, m_trk_truth_y);
1858 ntuple_trk->addItem("trk_truth_z", m_trk_size, m_trk_truth_z);
1859 ntuple_trk->addItem("trk_truth_r", m_trk_size, m_trk_truth_r);
1860 ntuple_trk->addItem("trk_truth_cosTheta", m_trk_size, m_trk_truth_cosTheta);
1861 ntuple_trk->addItem("trk_truth_Xc", m_trk_size, m_trk_truth_Xc);
1862 ntuple_trk->addItem("trk_truth_Yc", m_trk_size, m_trk_truth_Yc);
1863 ntuple_trk->addItem("trk_truth_R", m_trk_size, m_trk_truth_R);
1864
1865 } else { log << MSG::ERROR << "Cannot book tuple mdcHoughFinder/trk" <<endmsg;
1866 return StatusCode::FAILURE;
1867 }
1868 }
1869 return StatusCode::SUCCESS;
1870}
bool sortCluster(const RecCgemCluster *clusterA, const RecCgemCluster *clusterB)
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const double alpha
HepGeom::Point3D< double > HepPoint3D
Definition: Gam4pikp.cxx:37
double sin(const BesAngle a)
double cos(const BesAngle a)
std::vector< HoughRecHit > recHitCol
vector< TrkRecoTrk * > vectrk_for_clean
Definition: Hough3D.cxx:5
ObjectVector< RecMdcHit > RecMdcHitCol
SmartRefVector< RecCgemCluster > ClusterRefVec
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition: KKsem.h:33
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
HepVector bes2barbar(HepVector a)
HepVector barbar2bes(HepVector a)
bool sortCluster(const RecCgemCluster *clusterA, const RecCgemCluster *clusterB)
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
HepVector barbar2bes(HepVector a)
#define M_PI
Definition: TConstant.h:4
void start(void)
Definition: BesTimer.cxx:27
void stop(void)
Definition: BesTimer.cxx:39
void setHelix(double helix[5])
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.
static void setContext(TrkContextEv *context)
static void setGeomSvc(const CgemGeomSvc *cgemGeomSvc)
static void setCalib(const MdcCalibFunSvc *mdcCalibFunSvc)
static void setContext(TrkContextEv *context)
static void setCalib(const MdcCalibFunSvc *mdcCalibFunSvc)
static void setGeomSvc(const CgemGeomSvc *cgemGeomSvc)
int addTruthInfo(std::map< int, const HepVector > mcTkPars)
const std::vector< HoughHit > & getList() const
int addCgemClusterList(RecCgemClusterCol *cgemClusterVec)
static void setMdcGeomSvc(MdcGeomSvc *mdcGeomSvc)
static void setMdcCalibFunSvc(MdcCalibFunSvc *mdcCalibFunSvc)
static void setCgemGeomSvc(CgemGeomSvc *cgemGeomSvc)
void setMcPar(std::map< int, const HepVector > mcTkPars)
void setMdcHit(const vector< MdcHit * > *mdchit)
virtual BesTimer * addItem(const std::string &name)=0
static MdcDetector * instance()
Definition: MdcDetector.cxx:21
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 printRecMdcTrackCol() const
void remove(MdcTrack *atrack)
static void readMCppTable(std::string filenm)
void setVecClusters(ClusterRefVec vecclusters)
Definition: RecMdcTrack.cxx:86
void setVecHits(HitRefVec vechits)
Definition: RecMdcTrack.cxx:80
virtual TrkExchangePar helix(double fltL) const =0
virtual int nHit(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
const TrkFit * fitResult() const
Definition: TrkRecoTrk.cxx:387