CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
Hough.cxx
Go to the documentation of this file.
1#include "GaudiKernel/SmartDataPtr.h"
2#include "GaudiKernel/Bootstrap.h"
3#include "GaudiKernel/IDataManagerSvc.h"
4#include "GaudiKernel/IDataProviderSvc.h"
5#include "GaudiKernel/IPartPropSvc.h"
6
10#include "McTruth/McParticle.h"
11#include "HepPDT/ParticleDataTable.hh"
13#include "MdcRecoUtil/Pdt.h"
15#include "Identifier/CgemID.h"
16#include "Identifier/MdcID.h"
17#include "MdcGeom/MdcDetector.h"
20#include "TrkBase/TrkRep.h"
21#include "TrkBase/TrkDifTraj.h"
23
24#include <math.h>
25#include <iostream>
26#include <fstream>
27
28class TrkRep;
29using namespace std;
30
31HoughFinder::HoughFinder(const std::string& name, ISvcLocator* pSvcLocator):Algorithm(name, pSvcLocator)
32{
33 declareProperty("debug", m_debug = 0);
34 declareProperty("cgem", m_cgem = 1);
35 declareProperty("mcTruth", m_mcTruth = 0);
36 declareProperty("fillNTuple", m_fillNTuple= 0);
37 declareProperty("trackCharge", m_trackCharge = 0);
38 declareProperty("findPeakMethod",m_findPeakMethod=0);
39
40 //declareProperty("nStep_xy", m_nStep_xy = 1);
41 //declareProperty("xBin_xy", m_xBin_xy);
42 //declareProperty("yBin_xy", m_yBin_xy);
43 //declareProperty("xExtend_xy", m_xExtend_xy);
44 //declareProperty("yExtend_xy", m_yExtend_xy);
45 //declareProperty("nVote_xy", m_nVote_xy);
46 //declareProperty("nRMS_xy", m_nRMS_xy);
47 //declareProperty("xInclude_xy", m_xInclude_xy = 2);
48 //declareProperty("yInclude_xy", m_yInclude_xy = 2);
49
50 //declareProperty("nStep_sz", m_nStep_sz = 1);
51 //declareProperty("xBin_sz", m_xBin_sz);
52 //declareProperty("yBin_sz", m_yBin_sz);
53 //declareProperty("xExtend_sz", m_xExtend_sz);
54 //declareProperty("yExtend_sz", m_yExtend_sz);
55 //declareProperty("nVote_sz", m_nVote_sz);
56 //declareProperty("nRMS_sz", m_nRMS_sz);
57 //declareProperty("xInclude_sz", m_xInclude_sz = 2);
58 //declareProperty("yInclude_sz", m_yInclude_sz = 2);
59
60 //read raw data setup
61 declareProperty("keepBadTdc", m_keepBadTdc = 0);
62 declareProperty("dropHot", m_dropHot = 0);
63 declareProperty("keepUnmatch", m_keepUnmatch = 0);
64 declareProperty("driftTimeUpLimit", m_driftTimeUpLimit = 1500);
65 //declareProperty("",m_ = 0);
66 declareProperty("pdtFile", m_pdtFile = "pdt.table");
67
68 // tests by llwang
69 declareProperty("nBinTheta", m_nBinTheta=100 );
70 declareProperty("nBinRho", m_nBinRho=50 );
71 declareProperty("rhoRange", m_rhoRange = 0.1);
72 declareProperty("ExtPeak_theta",m_ExtPeak_theta= 4);
73 declareProperty("ExtPeak_rho", m_ExtPeak_rho= 4);
74 declareProperty("shareHitRate", m_shareHitRate = 0.7);
75
76 declareProperty("nBinTanl", m_nBinTanl = 100);
77 declareProperty("nBinDz", m_nBinDz = 100);
78 declareProperty("ExtPeak_tanl", m_ExtPeak_tanl = 1);
79 declareProperty("ExtPeak_dz", m_ExtPeak_dz = 1);
80 declareProperty("filter", m_filter= 0);
81 declareProperty("eventFile", m_evtFile= "EventList.txt");
82 declareProperty("fitFlag", m_fitFlag= 3);
83 declareProperty("storeFlag", storeFlag=1);
84 declareProperty("checkHits", m_checkHits=1);
85 declareProperty("Layer", Layer=20);
86 declareProperty("clearTrack", m_clearTrack=1);
87 declareProperty("useCgemInGlobalFit",m_useCgemInGlobalFit=3);
88 declareProperty("printFlag", printFlag=0);
89 declareProperty("removeNOuterHits", m_removeNOuterHits = 0);
90
91 // --- cuts for circle
92 declareProperty("circle_chiCut", m_circle_chiCut=25.0);
93
94 // --- cuts to combine tracks
95 declareProperty("drCut_combine", m_drCut=2.0);
96 declareProperty("phi0Cut_combine", m_phi0Cut=0.2);
97 declareProperty("kappaCut_combine",m_kappaCut=1.5);
98 declareProperty("dzCut_combine", m_dzCut=5.0);
99 declareProperty("tanlCut_combine", m_tanlCut=0.5);
100
101 // --- cuts for hits saved in RecMdcTrack
102 declareProperty("chi2CutHits", m_chi2CutHits=25);
103
104 m_maxFireLayer = -1;
105 m_totEvtProcessed=0;
106}
107
109{
110 MsgStream log(msgSvc(), name());
111 log << MSG::INFO << "HoughFinder::initialize()" << endreq;
112 StatusCode sc;
113
114 // --- RawData
115 IRawDataProviderSvc* irawDataProviderSvc;
116 sc = service ("RawDataProviderSvc", irawDataProviderSvc);
117 m_rawDataProviderSvc = dynamic_cast<RawDataProviderSvc*> (irawDataProviderSvc);
118 if ( sc.isFailure() ){
119 log << MSG::ERROR << name()<<" Could not load RawDataProviderSvc!" << endreq;
120 return StatusCode::FAILURE;
121 }
122
123
124 // --- MDC Geometry
125 IMdcGeomSvc* imdcGeomSvc;
126 sc = service ("MdcGeomSvc", imdcGeomSvc);
127 m_mdcGeomSvc = dynamic_cast<MdcGeomSvc*> (imdcGeomSvc);
128 if ( sc.isFailure() ){
129 log << MSG::ERROR << "Could not load MdcGeoSvc!" << endreq;
130 return StatusCode::FAILURE;
131 }
132
133 // --- MdcCalibFunSvc
134 IMdcCalibFunSvc* imdcCalibSvc;
135 sc = service ("MdcCalibFunSvc", imdcCalibSvc);
136 m_mdcCalibFunSvc = dynamic_cast<MdcCalibFunSvc*>(imdcCalibSvc);
137 if ( sc.isFailure() ){
138 log << MSG::ERROR << "Could not load MdcCalibFunSvc!" << endreq;
139 return StatusCode::FAILURE;
140 }
141
142 if(m_cgem){
143 // --- CGEM geometry
144 ICgemGeomSvc* icgemGeomSvc;
145 sc = service ("CgemGeomSvc", icgemGeomSvc);
146 m_cgemGeomSvc = dynamic_cast<CgemGeomSvc*> (icgemGeomSvc);
147 if ( sc.isFailure() ){
148 log << MSG::ERROR << "Could not load CgemGeomSvc!" << endreq;
149 return StatusCode::FAILURE;
150 }
151
152 // --- CgemCalibFunSvc
153 ICgemCalibFunSvc* icgemCalibSvc;
154 sc = service ("CgemCalibFunSvc", icgemCalibSvc);
155 m_cgemCalibFunSvc = dynamic_cast<CgemCalibFunSvc*>(icgemCalibSvc);
156 if ( sc.isFailure() ){
157 log << MSG::ERROR << "Could not load CgemCalibFunSvc!" << endreq;
158 return StatusCode::FAILURE;
159 }
160
161 }
162
163 // --- MagneticFieldSvc
164 sc = service ("MagneticFieldSvc",m_pIMF);
165 if( sc.isFailure() ) {
166 log << MSG::ERROR << "Unable to open Magnetic field service"<<endreq;
167 return StatusCode::FAILURE;
168 }
169 m_bfield = new BField(m_pIMF);
170 //log << MSG::INFO << "field z = "<<m_bfield->bFieldNominal()<< endreq;
171 m_trkContextEv = new TrkContextEv(m_bfield);
172 if(m_debug==5) cout<<"field z = "<<m_bfield->bFieldNominal()<< endl;
173
174 m_mdcDetector = new MdcDetector();
175 //read pdt
176 Pdt::readMCppTable(m_pdtFile);
177
178 // --- Mdc Print Service
179 //IMdcPrintSvc* imdcPrintSvc;
180 //sc = service ("MdcPrintSvc", imdcPrintSvc);
181 //m_mdcPrintSvc = dynamic_cast<MdcPrintSvc*> (imdcPrintSvc);
182 //if ( sc.isFailure() ){
183 //log << MSG::FATAL << "Could not load MdcPrintSvc!" << endreq;
184 //return StatusCode::FAILURE;
185 //}
186
187 // --- Bes Timer Service
188 //sc = service( "BesTimerSvc", m_timersvc);
189 //if( sc.isFailure() ) {
190 //log << MSG::WARNING << " Unable to locate BesTimerSvc" << endreq;
191 //return StatusCode::FAILURE;
192 //}
193 //m_timer_all = m_timersvc->addItem("Execution");
194 //m_timer_all->propName("nExecution");
195
196 HoughHit::setMdcGeomSvc(m_mdcGeomSvc);
197 HoughHit::setMdcCalibFunSvc(m_mdcCalibFunSvc);
198 HoughHit::setCgemGeomSvc(m_cgemGeomSvc);
199 HoughHit::setCgemCalibFunSvc(m_cgemCalibFunSvc);
200 HoughHit::setMdcDetector(m_mdcDetector);
203
204 m_roughRhoThetaMap=TH2D("roughRhoThetaMap","roughRhoThetaMap",m_nBinTheta,0.,M_PI, m_nBinRho, -1.*m_rhoRange, m_rhoRange);
205 //m_tanlRange = 0.93/sqrt(1-0.93*0.93);//FIXME
206 m_tanlRange = 3.0;//FIXME
207 m_dzRange = 50;
208 m_roughTanlDzMap = TH2D("roughTanlDzMap","roughTanlDzMap",m_nBinTanl,-1.*m_tanlRange,m_tanlRange,m_nBinDz,-1.*m_dzRange,m_dzRange);
209
210 const int nPt=12;
211 double rho[nPt] = {0.07, 0.056,0.045,0.038,0.0335,0.03,0.0198,0.0148,0.0074,0.00376,0.00303,0.00157};
212 double cut1_Cgem_99[12]={-2.14,-1.36, -0.6 , -0.46, -0.35, -0.59, -0.32, -0.26, -0.22, -0.21, -0.21, -0.211};
213 double cut2_Cgem_99[12]={ 0.5 , 1.77, 1.99, 1.94, 1.99, 1.9 , 0.31, 0.27, 0.24, 0.23, 0.23, 0.222};
214 double cut1_ODC1_99[12]={-1.28,-0.71, -0.58, -0.62, -0.64, -0.68, -0.18, -0.14, -0.11, -0.1 , -0.1 , -0.11 };
215 double cut2_ODC1_99[12]={ 0.9 , 0.74, 0.42, 0.37, 0.32, 0.37, 0.28, 0.25, 0.24, 0.24, 0.24, 0.23};
216 double cut1_ODC2_99[12]={ -2.14, -1.25, -1.28, -0.86, -0.47, -0.78, -0.36, -0.44, -0.61, -0.67, -0.64, -0.82 };
217 double cut2_ODC2_99[12]={ -1.35, 0.55 , 0.53 , 0.83 , 0.85 , 0.83 , 0.38 , 0.55 , 0.49 , 0.46 , 0.49 , 0.4};
218 m_cut1_cgem = new TGraph(nPt, rho, cut1_Cgem_99);
219 m_cut2_cgem = new TGraph(nPt, rho, cut2_Cgem_99);
220 m_cut1_ODC1 = new TGraph(nPt, rho, cut1_ODC1_99);
221 m_cut2_ODC1 = new TGraph(nPt, rho, cut2_ODC1_99);
222 m_cut1_ODC2 = new TGraph(nPt, rho, cut1_ODC2_99);
223 m_cut2_ODC2 = new TGraph(nPt, rho, cut2_ODC2_99);
224
225
226 int s(0),l(0),npt(0);
227 double momenta[100] = {0};
228 double cuts[2][43][100] = {0};
229 string cutFilePath = getenv("HOUGHTRANSALGROOT");
230 cutFilePath += "/share/cut.txt";
231 ifstream fin(cutFilePath.c_str(), ios::in);
232 //cout<<"cutfiledir:"<<cutFilePath.c_str()<<endl;
233 //ifstream fin("/workfs/bes/huangzhen/workarea/CgemBoss/6.6.5.c/Reconstruction/HoughFinder/HoughFinder-00-00-13/share/cut.txt",ios::in);
234 if (!fin.good())
235 cout << "Error in " << __FILE__<<" when opening "<<cutFilePath.c_str()<<endl;
236 bool firstline(true);
237 string strcom;
238 while(std::getline(fin, strcom)){
239 if(firstline){
240 fin >> npt
241 >> momenta[0] >> momenta[1] >> momenta[2] >> momenta[3] >> momenta[4] >> momenta[5] >> momenta[6] >> momenta[7] >> momenta[8] >> momenta[9]
242 >> momenta[10] >> momenta[11] >> momenta[12] >> momenta[13] >> momenta[14] >> momenta[15] >> momenta[16] >> momenta[17] >> momenta[18] >> momenta[19]
243 >> momenta[20] >> momenta[21] >> momenta[22] >> momenta[23] >> momenta[24] >> momenta[25] >> momenta[26] >> momenta[27] >> momenta[28] >> momenta[29]
244 >> momenta[30] >> momenta[31] >> momenta[32] >> momenta[33] >> momenta[34] >> momenta[35] >> momenta[36] >> momenta[37] >> momenta[38] >> momenta[39]
245 >> momenta[40] >> momenta[41] >> momenta[42] >> momenta[43] >> momenta[44] >> momenta[45] >> momenta[46] >> momenta[47] >> momenta[48] >> momenta[49]
246 >> momenta[50] >> momenta[51] >> momenta[52] >> momenta[53] >> momenta[54] >> momenta[55] >> momenta[56] >> momenta[57] >> momenta[58] >> momenta[59]
247 >> momenta[60] >> momenta[61] >> momenta[62] >> momenta[63] >> momenta[64] >> momenta[65] >> momenta[66] >> momenta[67] >> momenta[68] >> momenta[69]
248 >> momenta[70] >> momenta[71] >> momenta[72] >> momenta[73] >> momenta[74] >> momenta[75] >> momenta[76] >> momenta[77] >> momenta[78] >> momenta[79]
249 >> momenta[80] >> momenta[81] >> momenta[82] >> momenta[83] >> momenta[84] >> momenta[85] >> momenta[86] >> momenta[87] >> momenta[88] >> momenta[89]
250 >> momenta[90] >> momenta[91] >> momenta[92] >> momenta[93] >> momenta[94] >> momenta[95] >> momenta[96] >> momenta[97] >> momenta[98] >> momenta[99]
251 ;
252 firstline = false;
253 continue;
254 }
255 fin >> s >> l;
256 fin >> cuts[s][l][0] >> cuts[s][l][1] >> cuts[s][l][2] >> cuts[s][l][3] >> cuts[s][l][4] >> cuts[s][l][5] >> cuts[s][l][6] >> cuts[s][l][7] >> cuts[s][l][8] >> cuts[s][l][9]
257 >> cuts[s][l][10] >> cuts[s][l][11] >> cuts[s][l][12] >> cuts[s][l][13] >> cuts[s][l][14] >> cuts[s][l][15] >> cuts[s][l][16] >> cuts[s][l][17] >> cuts[s][l][18] >> cuts[s][l][19]
258 >> cuts[s][l][20] >> cuts[s][l][21] >> cuts[s][l][22] >> cuts[s][l][23] >> cuts[s][l][24] >> cuts[s][l][25] >> cuts[s][l][26] >> cuts[s][l][27] >> cuts[s][l][28] >> cuts[s][l][29]
259 >> cuts[s][l][30] >> cuts[s][l][31] >> cuts[s][l][32] >> cuts[s][l][33] >> cuts[s][l][34] >> cuts[s][l][35] >> cuts[s][l][36] >> cuts[s][l][37] >> cuts[s][l][38] >> cuts[s][l][39]
260 >> cuts[s][l][40] >> cuts[s][l][41] >> cuts[s][l][42] >> cuts[s][l][43] >> cuts[s][l][44] >> cuts[s][l][45] >> cuts[s][l][46] >> cuts[s][l][47] >> cuts[s][l][48] >> cuts[s][l][49]
261 >> cuts[s][l][50] >> cuts[s][l][51] >> cuts[s][l][52] >> cuts[s][l][53] >> cuts[s][l][54] >> cuts[s][l][55] >> cuts[s][l][56] >> cuts[s][l][57] >> cuts[s][l][58] >> cuts[s][l][59]
262 >> cuts[s][l][60] >> cuts[s][l][61] >> cuts[s][l][62] >> cuts[s][l][63] >> cuts[s][l][64] >> cuts[s][l][65] >> cuts[s][l][66] >> cuts[s][l][67] >> cuts[s][l][68] >> cuts[s][l][69]
263 >> cuts[s][l][70] >> cuts[s][l][71] >> cuts[s][l][72] >> cuts[s][l][73] >> cuts[s][l][74] >> cuts[s][l][75] >> cuts[s][l][76] >> cuts[s][l][77] >> cuts[s][l][78] >> cuts[s][l][79]
264 >> cuts[s][l][80] >> cuts[s][l][81] >> cuts[s][l][82] >> cuts[s][l][83] >> cuts[s][l][84] >> cuts[s][l][85] >> cuts[s][l][86] >> cuts[s][l][87] >> cuts[s][l][88] >> cuts[s][l][89]
265 >> cuts[s][l][90] >> cuts[s][l][91] >> cuts[s][l][92] >> cuts[s][l][93] >> cuts[s][l][94] >> cuts[s][l][95] >> cuts[s][l][96] >> cuts[s][l][97] >> cuts[s][l][98] >> cuts[s][l][99]
266 ;
267 if(fin.peek()<0)break;
268 }
269 for(int is=0;is<=1;is++){
270 for(int il=0;il<43;il++){
271 TGraph* gr = new TGraph();
272 int point(0);
273 //cout<<il<<" ";
274 for(int ipt=0;ipt<npt;ipt++){
275 //cout<<cuts[is][il][ipt]<<" ";
276 if(fabs(cuts[is][il][ipt])<1e-6)continue;
277 //cut[is][il]->SetPoint(point,momenta[ipt]/1000.,cuts[is][il][ipt]);
278 gr->SetPoint(point,momenta[ipt]/1000.,cuts[is][il][ipt]);
279 point++;
280 }
281 if(point>0)HoughTrack::m_cut[is][il] = gr;
282 //cout<<endl;
283 }
284 }
285
286
287 if(m_fillNTuple) sc = bookTuple();
288 if ( sc.isFailure() ){
289 log << MSG::FATAL << "Could not book Tuple !" << endreq;
290 return StatusCode::FAILURE;
291 }
292
293
294 myDotsHelixFitter.initialize();
295
296 return StatusCode::SUCCESS;
297}
298
300{
301 MsgStream log(msgSvc(), name());
302 log << MSG::INFO << "HoughFinder::execute()" << endreq;
303 cout.precision(6);
304
305
306 //cout<<"line "<<__LINE__<<endl;
307 // --- Get event header
308 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
309 if(!eventHeader){
310 log << MSG::ERROR << "Could not find Event Header" << endreq;
311 return StatusCode::FAILURE;
312 }
313 m_run = eventHeader->runNumber();
314 m_event = eventHeader->eventNumber();
315 m_totEvtProcessed++; //if(m_totEvtProcessed%100==0) cout<<"HoughFinder: "<<m_totEvtProcessed<<" events processed."<<endl;
316
317 myDotsHelixFitter.updateBField();
318
319 //cout<<"line "<<__LINE__<<endl;
320
321 // --- event start time
322 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
323 if(!evTimeCol){
324 log << MSG::ERROR << "Could not retrieve RecEsTimeCol" << endreq;
325 return StatusCode::FAILURE;
326 }
327 m_bunchT0 = 0;
328 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
329 if (iter_evt != evTimeCol->end()){
330 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;//m_bunchT0-s, getTest-ns
331 //cout<<"this event T0 = "<<m_bunchT0<<endl;
332 }
333
334 // --- clear, register and store reconstructed track
335 registerTrack(m_trackList_tds,m_hitList_tds);
336
337
338 //cout<<"line "<<__LINE__<<endl;
339 if(m_filter){
340 ifstream lowPt_Evt;
341 lowPt_Evt.open(m_evtFile.c_str());
342 vector<int> evtlist;
343 int evtNum;
344 while( lowPt_Evt >> evtNum) {
345 evtlist.push_back(evtNum);
346 }
347 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),m_event);
348 if(iter_evt == evtlist.end()){
349 setFilterPassed(false);
350 return StatusCode::SUCCESS;
351 }
352 else{
353 setFilterPassed(true);
354 }
355 }
356 //if(m_event<2000||m_event>3000){
357 //setFilterPassed(false);
358 //return StatusCode::SUCCESS;
359 //}
360
361 if(m_debug==5)
362 {
363 //cout<<endl;
364 cout<<"===================================================================================================="<<endl;
365 cout<<"run:"<<m_run<<" , event: "<<m_event<<endl;
366 cout<<"field z = "<<m_bfield->bFieldNominal()<< endl;
367 //cout<<m_event<<" , ";
368 //cout<<endl;
369 }
370
371 //cout<<"line "<<__LINE__<<endl;
372 // --- prepare hits for reconstruction
373 int nHit = makeHoughHitList();
374
375 //cout<<"line "<<__LINE__<<endl;
376 int nMcHit;
377 if(m_run<0&&m_mcTruth){
378 int nMcHit = getMcHitCol();
379 //cout<<"nMcHit "<<nMcHit<<endl;
380 if(printFlag)cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ McParticle @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;
382 if(printFlag)cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ McParticle @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;
383 if(printFlag)cout<<endl;
384 if(printFlag)cout<<endl;
385 if(printFlag)cout<<endl;
386 //halfCircle(m_mcTrackCol,m_mcHitCol);
387 }
388
389 //cout<<"line "<<__LINE__<<endl;
390 searchCircle();
391 //cout<<"ntracks:"<<m_houghTrackList.size()<<endl;
392 //cout<<"line "<<__LINE__<<endl;
393 checkHot(m_houghTrackList); // remove tracks with too many shared hits (if >70%)
394 //cout<<"line "<<__LINE__<<endl;
395 solveSharedHits(m_XHoughHitList); // solve hits sharing by smaller distance
396 //updateXHitsStatistics(m_houghTrackList);
397 //checkTrack(m_houghTrackList);
398 //cout<<"line "<<__LINE__<<endl;
399 associateVHits();
400 //cout<<"line "<<__LINE__<<endl;
401 if(printFlag)cout<<"################################################## HoughTrack ##################################################"<<endl;
402 if(storeFlag==1)storeTracks(m_trackList_tds, m_hitList_tds, m_houghTrackList);
403 else
404 if(storeFlag==2)storeTrack(m_houghTrackList,m_trackList_tds,m_hitList_tds);
405 else
406 if(storeFlag==3)storeRecTracks(m_trackList_tds, m_hitList_tds, m_houghTrackList);
407 if(printFlag)cout<<"################################################## HoughTrack ##################################################"<<endl;
408 if(printFlag)cout<<endl;
409 if(printFlag)cout<<endl;
410 if(printFlag)cout<<endl;
411 //cout<<"line "<<__LINE__<<endl;
412
413 if(m_fillNTuple)dumpHit();
414 if(m_fillNTuple==1)dumpHoughTrack();
415 if(m_fillNTuple==1)dumpHoughEvent();
416 if(m_fillNTuple==2)dumpTdsTrack();
417 if(m_fillNTuple==2)dumpTdsEvent();
418 //cout<<"line "<<__LINE__<<endl;
419
420 if(printFlag)cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ TdsTrack $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
422 if(printFlag)cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ TdsTrack $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
423 if(printFlag)cout<<endl;
424 if(printFlag)cout<<endl;
425 if(printFlag)cout<<endl;
426
427 if(printFlag)cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& HoughHit &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
429 if(printFlag)cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& HoughHit &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
430 if(printFlag)cout<<endl;
431 if(printFlag)cout<<endl;
432 if(printFlag)cout<<endl;
433
434 clearTrack(m_houghTrackList);
435 //cout<<"line "<<__LINE__<<endl;
436
437 clearMemory();
438 //cout<<"line "<<__LINE__<<endl;
439 if(m_debug==5) cout<<endl;
440
441 return StatusCode::SUCCESS;
442}// <-- execute()
443
445{
446 MsgStream log(msgSvc(), name());
447 log << MSG::INFO << "HoughFinder::finalize()" << endreq;
448 return StatusCode::SUCCESS;
449}
450
452{
453 return fabs(trk1.pt())>fabs(trk2.pt());
454}
455
457{
458 MsgStream log(msgSvc(), name());
459 int nHit(0);
460 if(!(m_mdcHitCol.empty())) m_mdcHitCol.clear();
461 if(!(m_houghHitList.empty())) m_houghHitList.clear();
462 if(!(m_XHoughHitList.empty())) m_XHoughHitList.clear();
463 if(!(m_VHoughHitList.empty())) m_VHoughHitList.clear();
464
465 if(m_cgem){
466 // --- RecCgemCluster
467 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(), "/Event/Recon/RecCgemClusterCol");
468 if(!recCgemClusterCol){
469 log << MSG::ERROR << "Could not retrieve RecCgemClusterCol" << endreq;
470 }else{
471 RecCgemClusterCol::iterator cgemClusterIter = recCgemClusterCol->begin();
472 m_recCgemClusterColBegin=cgemClusterIter;
473 for (;cgemClusterIter != recCgemClusterCol->end(); cgemClusterIter++,nHit++){
474 const RecCgemCluster* recCgemCluster = (*cgemClusterIter);
475 //m_recCgemCluster = (*cgemClusterIter);
476 HoughHit hit(recCgemCluster, m_bunchT0, nHit);
477 m_houghHitList.push_back(hit);
478 if(hit.getLayer()>m_maxFireLayer)m_maxFireLayer = hit.getLayer();
479 }
480 }
481 }
482
483 uint32_t getDigiFlag = 0;
484 if(m_dropHot)getDigiFlag |= MdcRawDataProvider::b_dropHot;
485 if(m_keepBadTdc) getDigiFlag |= MdcRawDataProvider::b_keepBadTdc;
486 if(m_keepUnmatch) getDigiFlag |= MdcRawDataProvider::b_keepUnmatch;
487 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec(getDigiFlag);
488
489 MdcDigiVec::iterator mdcDigiIter = mdcDigiVec.begin();
490 for (;mdcDigiIter != mdcDigiVec.end(); mdcDigiIter++,nHit++){
491 const MdcDigi* mdcDigi = (*mdcDigiIter);
492 HoughHit hit(mdcDigi, m_bunchT0, nHit);
493 if(fabs(hit.driftTime())>m_driftTimeUpLimit) continue;
494 MdcHit *mdcHit= new MdcHit(mdcDigi,m_mdcDetector);
495 hit.setMdcHit(mdcHit);
496
497 m_mdcHitCol.push_back(mdcHit);
498 m_houghHitList.push_back(hit);
499 if(hit.getLayer()>m_maxFireLayer)m_maxFireLayer = hit.getLayer();
500 }
501
502 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
503 int flag=hitIt->getFlag();
504 if(hitIt->getHitType()==HoughHit::CGEMHIT){
505 if(flag==0)m_XHoughHitList.push_back(&(*hitIt));
506 if(flag==2)m_VHoughHitList.push_back(&(*hitIt));
507 }
508 if(hitIt->getHitType()==HoughHit::MDCHIT){
509 if(flag==0)m_XHoughHitList.push_back(&(*hitIt));
510 else m_VHoughHitList.push_back(&(*hitIt));
511 }
512 }
513 //for(vector<HoughHit*>::iterator hitIt = m_XHoughHitList.begin(); hitIt != m_XHoughHitList.end(); hitIt++){
514 //(*hitIt)->print();
515 //}
516 //for(vector<HoughHit*>::iterator hitIt = m_VHoughHitList.begin(); hitIt != m_VHoughHitList.end(); hitIt++){
517 //(*hitIt)->print();
518 //}
519
520 return nHit;
521}
522
524{
525 MsgStream log(msgSvc(), name());
526 int nMcHit(0);
527 if(!(m_mcHitCol.empty()))m_mcHitCol.clear();
528
529 // --- get cgemMcHit
530 if(m_cgem){
531 SmartDataPtr<CgemMcHitCol> cgemMcHitCol(eventSvc(), "/Event/MC/CgemMcHitCol");
532 if (!cgemMcHitCol){
533 log << MSG::ERROR << "Could not retrieve CgemMcHitCol" << endreq;
534 }else{
535 CgemMcHitCol::iterator cgemMcHitIt = cgemMcHitCol->begin();
536 for(;cgemMcHitIt != cgemMcHitCol->end();cgemMcHitIt++,nMcHit++){
537 const CgemMcHit* cgemMcHit = (*cgemMcHitIt);
538 HoughHit hit(cgemMcHit,m_bunchT0,nMcHit);
539 m_mcHitCol.push_back(hit);
540 HoughHit* phit = &(*m_mcHitCol.rbegin());
541
542 // --- match fired strip ID between CemgMcHit and RecCgemCluster
543 vector<int> xFireStripID;
544 vector<int> vFireStripID;
545 int sheet;
546 TArrayI identifier = phit->getCgemMcHit()->GetIdentifier();
547 for(int ii = 0; ii < identifier.GetSize(); ii++){
548 //const Identifier ident = Identifier(identifier.GetAt(ii));
549 const Identifier ident = Identifier(identifier.At(ii));
550 if(CgemID::is_xstrip(ident))xFireStripID.push_back(CgemID::strip(ident));
551 else vFireStripID.push_back(CgemID::strip(ident));
552 sheet = CgemID::sheet(ident);
553 //cout
554 //<< " hitID:" << phit->getHitID()
555 //<< " layerID=" << CgemID::layer(ident)
556 //<< " sheetID=" << CgemID::sheet(ident)
557 //<< " isXstrip=" << CgemID::is_xstrip(ident)
558 //<< " stripID=" << CgemID::strip(ident)
559 //<<endl;
560 }
561 sort(xFireStripID.begin(),xFireStripID.end());
562 sort(vFireStripID.begin(),vFireStripID.end());
563 //vector<int>::iterator uniqueX = unique(xFireStripID.begin(),xFireStrip ID.end());
564 //vector<int>::iterator uniqueV = unique(vFireStripID.begin(),vFireStrip ID.end());
565 //xFireStripID.erase(uniqueX,xFireStripID.end());
566 //vFireStripID.erase(uniqueV,vFireStripID.end());
567 //for(vector<int>::iterator i = vFireStripID.begin();i!=vFireStripID.end();i++)cout<<*i<<endl;
568 //cout<<endl;
569
570 bool findX(false), findV(false);
571 const RecCgemCluster* xCluster = NULL;
572 const RecCgemCluster* vCluster = NULL;
573 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
574 if(hitIt->getHitType()!=HoughHit::CGEMHIT)continue;
575 const RecCgemCluster* recCgemCluster = hitIt->getCgemCluster();
576 if(recCgemCluster->getlayerid() != phit->getLayer())continue;
577 if(!(recCgemCluster->getflag()==0||recCgemCluster->getflag()==1))continue;
578 //if(recCgemCluster->getsheetid() != sheet)continue;
579 //if(recCgemCluster->getTrkId() != *(phit->getTrkID().begin())continue;
580 if(!findX){
581 findX = recCgemCluster->getflag() == 0
582 && xFireStripID.size() > 0
583 && recCgemCluster->getclusterflagb() == *(xFireStripID.begin())
584 && recCgemCluster->getclusterflage() == *(xFireStripID.rbegin());
585 if(findX){
586 xCluster = recCgemCluster;
587 hitIt->setPairHit(phit);
588 }
589 }
590 if(!findV){
591 findV = recCgemCluster->getflag() == 1
592 && vFireStripID.size() > 0
593 && recCgemCluster->getclusterflagb() == *(vFireStripID.begin())
594 && recCgemCluster->getclusterflage() == *(vFireStripID.rbegin());
595 if(findV){
596 vCluster = recCgemCluster;
597 hitIt->setPairHit(phit);
598 }
599 }
600
601 }
602
603 /// --- put match RecCgemCluster into CemgMcHit
604 if(findX&&findV){
605 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
606 if(hitIt->getHitType()!=HoughHit::CGEMHIT)continue;
607 const RecCgemCluster* recCgemCluster = hitIt->getCgemCluster();
608 if(recCgemCluster->getlayerid() != phit->getLayer())continue;
609 if(recCgemCluster->getflag()==0||recCgemCluster->getflag()==1)continue;
610 //if(recCgemCluster->getsheetid() != sheet)continue;
611 //if(recCgemCluster->getTrkId() != *(phit->getTrkID().begin())continue;
612 if(recCgemCluster->getclusterflagb() == xCluster->getclusterid()
613 && recCgemCluster->getclusterflage() == vCluster->getclusterid()){
614 phit->setCgemCluster(recCgemCluster);
615 phit->setWire(recCgemCluster->getclusterid());
616 phit->setFlag(recCgemCluster->getflag());
617 phit->setPairHit(&(*hitIt));
618 hitIt->setPairHit(phit);
619 }
620 }
621 }
622 else if(findX&&!findV){
623 phit->setCgemCluster(xCluster);
624 phit->setWire(xCluster->getclusterid());
625 phit->setFlag(xCluster->getflag());
626 }
627 else if(!findX&&findV){
628 phit->setCgemCluster(vCluster);
629 phit->setWire(vCluster->getclusterid());
630 phit->setFlag(vCluster->getflag());
631 }
632 }
633 }
634 }
635
636 // --- get mdcMcHit
637 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc(),"/Event/MC/MdcMcHitCol");
638 if(!mdcMcHitCol){
639 log << MSG::ERROR << "Could not retrieve MdcMcHitCol" << endreq;
640 }else{
641 MdcMcHitCol::iterator mdcMcHitIt = mdcMcHitCol->begin();
642 for(;mdcMcHitIt != mdcMcHitCol->end();mdcMcHitIt++,nMcHit++){
643 const MdcMcHit* mdcMcHit = (*mdcMcHitIt);
644 HoughHit hit(mdcMcHit,m_bunchT0,nMcHit);
645 m_mcHitCol.push_back(hit);
646 HoughHit* phit = &(*m_mcHitCol.rbegin());
647 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
648 if(hitIt->getHitType()!=HoughHit::MDCHIT)continue;
649 const MdcDigi* mdcDigi = hitIt->getDigi();
650 if(mdcDigi->identify() == phit->getMdcMcHit()->identify()){
651 phit->setDigi(mdcDigi);
652 phit->setPairHit(&(*hitIt));
653 hitIt->setPairHit(phit);
654 }
655 }
656 }
657 }
658
659 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
660 for(HitVector_Iterator mcHitIt = m_mcHitCol.begin(); mcHitIt != m_mcHitCol.end();mcHitIt++){
661 if(hitIt->getLayer()!=mcHitIt->getLayer())continue;
662 if(hitIt->getHitType() == HoughHit::CGEMHIT && mcHitIt->getHitType() == HoughHit::CGEMMCHIT){
663 if(mcHitIt->getCgemCluster()==NULL)continue;
664 int recClusterID(-1);
665 int mcClusterID(-2);
666 int recFlag = hitIt->getCgemCluster()->getflag();
667 int mcFlag = mcHitIt->getCgemCluster()->getflag();;
668 if(recFlag==mcFlag){
669 recClusterID = hitIt->getCgemCluster()->getclusterid();
670 mcClusterID = mcHitIt->getCgemCluster()->getclusterid();
671 }
672
673 if(recFlag==1&&mcFlag==2){
674 recClusterID = hitIt->getCgemCluster()->getclusterid();
675 mcClusterID = mcHitIt->getCgemCluster()->getclusterflage();
676 }
677
678 if(recFlag==0&&mcFlag==2){
679 recClusterID = hitIt->getCgemCluster()->getclusterid();
680 mcClusterID = mcHitIt->getCgemCluster()->getclusterflagb();
681 }
682
683 if(recFlag==2&&mcFlag==1){
684 recClusterID = hitIt->getCgemCluster()->getclusterflage();
685 mcClusterID = mcHitIt->getCgemCluster()->getclusterid();
686 }
687
688 if(recFlag==2&&mcFlag==0){
689 recClusterID = hitIt->getCgemCluster()->getclusterflagb();
690 mcClusterID = mcHitIt->getCgemCluster()->getclusterid();
691 }
692
693 if(recClusterID==mcClusterID){
694 hitIt->setPairHit(&(*mcHitIt));
695 hitIt->setCgemMcHit(mcHitIt->getCgemMcHit());
696 //mcHitIt->addPairHit(&(*hitIt));
697
698 //cout<<hitIt->getLayer()<<" "<<mcHitIt->getLayer()<<" "<<hitIt->getWire()<<" "<<mcHitIt->getWire()<<endl;
699 //cout<<hitIt->getDigi()->identify()<<" "<<mcHitIt->getMdcMcHit()->identify()<<endl;
700 //cout<<hitIt->getLayer()<<" "<<mcHitIt->getLayer()<<" ";
701 //cout<<hitIt->getWire()<<" "<<mcHitIt->getWire()<<endl;
702 //cout<<recFlag<<" "<<mcFlag<<" ";
703 //cout<<recClusterID<<" "<<mcClusterID<<endl;
704
705 //cout<<hitIt->getHitPosition();
706 //cout<<endl;
707 //cout<<mcHitIt->getHitPosition();
708 //cout<<endl;
709 //cout<<endl;
710 }
711 }
712 else if(hitIt->getHitType() == HoughHit::MDCHIT && mcHitIt->getHitType() == HoughHit::MDCMCHIT){
713 if(mcHitIt->getDigi()==NULL)continue;
714 //if(hitIt->getLayer() == mcHitIt->getLayer() && hitIt->getWire() == mcHitIt->getWire())
715 if(hitIt->getDigi()->identify() == mcHitIt->getDigi()->identify())
716 {
717 hitIt->setPairHit(&(*mcHitIt));
718 hitIt->setMdcMcHit(mcHitIt->getMdcMcHit());
719 //mcHitIt->addPairHit(&(*hitIt));
720 //cout<<hitIt->getLayer()<<" "<<hitIt->getWire()<<endl;
721 //cout<<mcHitIt->getLayer()<<" "<<mcHitIt->getWire()<<endl;
722 //cout<<endl;
723 //cout<<hitIt->getDigi()->identify()<<" "<<mcHitIt->getMdcMcHit()->identify()<<endl;
724 }
725 }
726 }
727 }
728 //for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
729 //if(hitIt->getHitType()!=HoughHit::MDCHIT)continue;
730 //cout<<hitIt->getLayer()<<" "<<hitIt->getWire()<<" ";
731 //if(hitIt->getPairHit()!=NULL){
732 //cout<<hitIt->getPairHit()->getHitID()<<" ";
733 //cout<<hitIt->getPairHit()->getLayer()<<" "<<hitIt->getPairHit()->getWire()<<" ";
734 //}
735 //cout<<endl;
736 //}
737
738 return nMcHit;
739}
740
742 const int maxCell[43] = {40,44,48,56, 64,72,80,80,
743 76,76,88,88, 100,100,112,112, 128,128,140,140,
744 160,160,160,160, 176,176,176,176, 208,208,208,208, 240,240,240,240,
745 256,256,256,256, 288,288,288 };
746 m_mcTrackCol.clear();
747 MsgStream log(msgSvc(), name());
748 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
749 if (!mcParticleCol) {
750 log << MSG::ERROR << "Could not find McParticle" << endreq;
751 }else{
752 bool psipDecay(false);
753 McParticleCol::iterator iter_mc = mcParticleCol->begin();
754 for (;iter_mc != mcParticleCol->end(); iter_mc++){
755 int trackIndex = (*iter_mc)->trackIndex();
756 int pid = (*iter_mc)->particleProperty();
757 bool primaryParticle = (*iter_mc)->primaryParticle();
758 bool leafParticle = (*iter_mc)->leafParticle();
759 bool decayFromGenerator = (*iter_mc)->decayFromGenerator();
760 bool decayInFlight = (*iter_mc)->decayInFlight();
761 HepLorentzVector initialPosition = (*iter_mc)->initialPosition();
762 HepLorentzVector initialFourMomentum = (*iter_mc)->initialFourMomentum();
763 //HepLorentzVector finalPosition = (*iter_mc)->finalPosition();
764 //HepLorentzVector finalFourMomentum = (*iter_mc)->finalFourMomentum();
765 unsigned int statusFlags = (*iter_mc)->statusFlags();
766 //string process = (*iter_mc)->getProcess();
767 //if(primaryParticle)continue;
768 //if(!decayFromGenerator)continue;
769 //if(pid==100443)psipDecay = true;
770 //if(!psipDecay) continue;
771 //if(!(fabs(pid)==11||fabs(pid)==211))continue;
772
773 string name;
774 int charge(0);
775 if( pid == 0 ) {
776 //cout << "Wrong particle id" <<endl;
777 continue;
778 }else{
779 IPartPropSvc* p_PartPropSvc;
780 static const bool CREATEIFNOTTHERE(true);
781 StatusCode PartPropStatus = service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
782 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
783 log << MSG::ERROR << "Could not initialize Particle Properties Service" << endreq;
784 }
785 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
786 if( p_particleTable->particle(pid) ){
787 name = p_particleTable->particle(pid)->name();
788 charge = p_particleTable->particle(pid)->charge();
789 }else if( p_particleTable->particle(-pid) ){
790 name = "anti " + p_particleTable->particle(-pid)->name();
791 charge = (-1)*p_particleTable->particle(-pid)->charge();
792 }
793 }
794
795 //cout
796 //<<setw(8)<<trackIndex
797 //<<setw(12)<<name
798 //<<setw(8)<<pid
799 //<<setw(8)<<primaryParticle
800 //<<setw(8)<<leafParticle
801 //<<setw(8)<<decayFromGenerator
802 //<<setw(8)<<decayInFlight
803 //<<setw(8)<<statusFlags
804 //<<endl;
805
806 HoughTrack track(charge,initialPosition.v(),initialFourMomentum.v(),trackIndex);
807 //HoughTrack* track = new HoughTrack(charge,initialPosition.v(),initialFourMomentum.v(),trackIndex);
808 HepPoint3D pivot(0,0,0);
809 track.pivot(pivot);
810
811 int nHot(0);
812 vector<HoughHit*> hotList;
813 vector<HoughHit>& hitList = m_mcHitCol;
814 for(HitVector_Iterator hitIt = hitList.begin(); hitIt != hitList.end();hitIt++){
815 vector<int> trkID = hitIt->getTrkID();
816 if(trkID[0]==track.getTrkID()){
817 if(hitIt->getHitType()==HoughHit::CGEMMCHIT){
818 track.addHitPnt(&(*hitIt));
819 track.addVecStereoHitPnt(&(*hitIt));
820 hotList.push_back(&(*hitIt));
821 }
822 if(hitIt->getHitType()==HoughHit::MDCMCHIT){
823 if(hitIt->getFlag()==0)track.addHitPnt(&(*hitIt));
824 else track.addVecStereoHitPnt(&(*hitIt));
825 hotList.push_back(&(*hitIt));
826 }
827 nHot++;
828 }
829 }
830 if(nHot>0)m_mcTrackCol.push_back(track);
831
832 ///*
833 bool classifyHotByHotLayer(false);
834 bool classifyHotByTrackCenter(true);
835 if(classifyHotByHotLayer){
836 int lastHitLayer(0);
837 int deltaLayer(0);
838 int halfCircle(0);
839 HoughHit* lastLayerHit;
840 vector<HoughHit*> hitOnLayer;
841 int nMdcHot(0);
842 for(vector<HoughHit*>::iterator hitIt = hotList.begin(); hitIt != hotList.end(); hitIt++){
843 if((*hitIt)->getHitType()!=HoughHit::MDCHIT)continue;
844 if(nMdcHot==0){//the first hit on track
845 hitOnLayer.clear();
846 hitOnLayer.push_back(*hitIt);
847 lastLayerHit = *hitIt;
848 lastHitLayer = (*hitIt)->getLayer();
849 deltaLayer = 0;
850 halfCircle = 1;
851 }else{
852 if((*hitIt)->getLayer()==lastHitLayer){//find hits on the same layer
853 hitOnLayer.push_back(*hitIt);
854 lastHitLayer = (*hitIt)->getLayer();
855 }else{//another layer hit
856 if(deltaLayer*((*hitIt)->getLayer()-lastHitLayer)>=0){//not the turn layer
857 for(vector<HoughHit*>::iterator iter = hitOnLayer.begin(); iter != hitOnLayer.end(); iter++){
858 (*iter)->setHalfCircle(halfCircle);
859 lastLayerHit = *iter;
860 }
861 }else{//the turn layer
862 halfCircle++;
863 int maxWireGap(0);
864 int turnPoint(0);
865 int deltaWire(0);
866 for(vector<HoughHit*>::iterator iter = hitOnLayer.begin(); iter != hitOnLayer.end(); iter++){
867 deltaWire = fabs((*iter)->getWire()-lastLayerHit->getWire());
868 if(deltaWire>(maxCell[(*iter)->getLayer()])/2) deltaWire = maxCell[(*iter)->getLayer()] - deltaWire;
869 if(deltaWire>maxWireGap){
870 maxWireGap = deltaWire;
871 turnPoint = iter - hitOnLayer.begin();
872 }
873 lastLayerHit = *iter;
874 }
875 deltaWire = fabs((*hitIt)->getWire()-lastLayerHit->getWire());
876 if(deltaWire>(maxCell[(*hitIt)->getLayer()])/2) deltaWire = maxCell[(*hitIt)->getLayer()] - deltaWire;
877 if(deltaWire>maxWireGap){
878 maxWireGap = deltaWire;
879 turnPoint = hitOnLayer.size();
880 }
881
882 if(maxWireGap>2){
883 for(vector<HoughHit*>::iterator iter = hitOnLayer.begin(); iter != hitOnLayer.end(); iter++){
884 int shift = iter-hitOnLayer.begin();
885 if(shift<turnPoint)(*iter)->setHalfCircle(halfCircle-1);
886 else (*iter)->setHalfCircle(halfCircle);
887 }
888 }else{
889 for(vector<HoughHit*>::iterator iter = hitOnLayer.begin(); iter != hitOnLayer.end(); iter++){
890 int shift = iter-hitOnLayer.begin();
891 if(shift<hitOnLayer.size()/2)(*iter)->setHalfCircle(halfCircle-1);
892 else (*iter)->setHalfCircle(halfCircle);
893 }
894 }
895 }
896 hitOnLayer.clear();
897 hitOnLayer.push_back(*hitIt);
898 lastHitLayer = (*hitIt)->getLayer();
899 deltaLayer = (*hitIt)->getLayer()-lastHitLayer;
900 }
901
902 }
903 nMdcHot++;
904 }
905 }
906 //*/
907 ///*
908 if(classifyHotByTrackCenter){
909 int cgemHalf(0), mdcHalf(0);
910 int cgemSign(0), mdcSign(0);
911 int half(0), sign(0);
912 for(vector<HoughHit*>::iterator hitIt = hotList.begin(); hitIt != hotList.end(); hitIt++){
913 //(*hitIt)->print();
914 if((*hitIt)->getHitType() == HoughHit::CGEMMCHIT){
915 if(track.judgeHalf(*hitIt) != cgemSign){
916 cgemHalf++;
917 cgemSign = track.judgeHalf(*hitIt);
918 half = cgemHalf;
919 sign = cgemSign;
920 }
921 }
922 else if((*hitIt)->getHitType() == HoughHit::MDCMCHIT){
923 if(track.judgeHalf(*hitIt) != mdcSign){
924 mdcHalf++;
925 mdcSign = track.judgeHalf(*hitIt);
926 half = mdcHalf;
927 sign = mdcSign;
928 }
929 }
930 (*hitIt)->setHalfCircle(half);
931 }
932 }
933 if(hotList.size()>0){
934 if(printFlag)track.print();
935 //track.printHot();
936 //cout<<endl;
937 }
938 for(vector<HoughHit*>::iterator hotIt = hotList.begin(); hotIt != hotList.end();hotIt++){
939 HoughHit* hitIt = *hotIt;
940 if(printFlag)hitIt->print();
941 //cout<<hitIt->getHitID();
942 //cout<<" ("<<hitIt->getLayer()<<", "<<hitIt->getWire()<<") "<<hitIt->getFlag();
943 //cout<<endl;
944 }
945 if(printFlag)if(hotList.size())cout<<endl;
946 }
947 sort(m_mcTrackCol.begin(),m_mcTrackCol.end(),largerPt);
948 //cout<<"N MCtrack: "<<m_mcTrackCol.size()<<endl;
949 for(vector<HoughTrack>::iterator trkIter=m_mcTrackCol.begin();trkIter!=m_mcTrackCol.end();trkIter++){
950 //trkIter->print();
951 }
952 }
953 return m_mcTrackCol.size();
954}
955
956int HoughFinder::fillHistogram(HoughHit* hit, TH2D* hitMap, int charge, int vote)
957{
958 //cout<<"fillHistogram "<<__LINE__<<endl;
959 int nBin = hitMap->GetXaxis()->GetNbins();
960 double xMin = hitMap->GetXaxis()->GetXmin();
961 double xMax = hitMap->GetXaxis()->GetXmax();
962 double yMin = hitMap->GetYaxis()->GetXmin();
963 double yMax = hitMap->GetYaxis()->GetXmax();
964 double dx = (xMax-xMin)/(nBin*vote)>1e-6?(xMax-xMin)/(nBin*vote):1e-6;
965 double x = xMin + dx/2;
966
967 int flag = hit->getFlag();
968 int nPoint(0);
969 if(flag==0){
970 double xHit = hit->getHitPosition().x();
971 double yHit = hit->getHitPosition().y();
972 double rHit = hit->getDriftDist();//drift distance
973 double denominator = xHit*xHit+yHit*yHit-rHit*rHit;
974
975 //double X1(0),Y1(0),X2(0),Y2(0),R(0);
976 double X1 = 2*xHit/denominator;
977 double Y1 = 2*yHit/denominator;
978 double X2 = 2*xHit/denominator;
979 double Y2 = 2*yHit/denominator;
980 double R = 2*rHit/denominator;
981
982 while(x<xMax){
983 double y1 = X1*cos(x) + Y1*sin(x) + R;
984 double y2 = X2*cos(x) + Y2*sin(x) - R;
985 double slope1 = -X1*sin(x) + Y1*cos(x);
986 double slope2 = -X2*sin(x) + Y2*cos(x);
987 double hitOnCircle1 = charge*slope1*y1;
988 double hitOnCircle2 = charge*slope2*y2;
989
990 bool cut(true);
991 cut = yMin<y1 && y1<yMax;
992 cut = cut && hitOnCircle1 <=0;
993 if(cut){
994 hitMap->Fill(x,y1);
995 nPoint++;
996 }
997
998 if(hit->getHitType()!=HoughHit::CGEMHIT) {
999 cut = yMin<y2 && y2<yMax;
1000 cut = cut && hitOnCircle2 <= 0;
1001 if(cut){
1002 //if(hit.getHitType() == HoughHit::CGEMHIT)continue;// comment by llwang
1003 //int bin = hitMap->FindBin(x,y2);
1004 //if(hitMap->GetBinContent(bin)>0)continue;
1005 hitMap->Fill(x,y2);
1006 nPoint++;
1007 }
1008 }
1009
1010 x += dx;
1011 }
1012 }else{
1013 vector<HoughHit::S_Z> sz = hit->getSZ();
1014 vector<HoughHit::S_Z>::iterator iter = sz.begin();
1015 for(;iter!=sz.end();iter++){
1016 double S = iter->first;
1017 double Z = iter->second;
1018 double dy = -S*dx;
1019 double y = -dy + Z;
1020 while(x<xMax){
1021 x += dx;
1022 y += dy;
1023 //y = S*cos(x) + Z*sin(x);
1024 bool cut(true);
1025 cut = yMin<y && y<yMax;
1026 if(cut){
1027 hitMap->Fill(x,y);
1028 nPoint++;
1029 }
1030 }
1031 }
1032 }
1033 //cout<<"fillHistogram "<<__LINE__<<endl;
1034 return nPoint;
1035}
1036
1037int HoughFinder::fillHistogram(HoughHit* hit, TH2D* hitMap, HoughTrack* trkCandi, int vote)
1038{
1039 int charge = trkCandi->getCharge();
1040 int nBin = hitMap->GetXaxis()->GetNbins();
1041 double xMin = hitMap->GetXaxis()->GetXmin();
1042 double xMax = hitMap->GetXaxis()->GetXmax();
1043 double yMin = hitMap->GetYaxis()->GetXmin();
1044 double yMax = hitMap->GetYaxis()->GetXmax();
1045 double dx = (xMax-xMin)/(nBin*vote)>1e-6?(xMax-xMin)/(nBin*vote):1e-6;// step size
1046 double x = xMin + dx/2;// first step
1047
1048 int flag = hit->getFlag();
1049 int nPoint(0);
1050 if(flag==0) // X-view hits
1051 {
1052 bool firstHalf = trkCandi->judgeHalf(hit)==1;
1053 if(!firstHalf) return 0;
1054 double xHit = hit->getHitPosition().x();
1055 double yHit = hit->getHitPosition().y();
1056 double rHit = hit->getDriftDist();//drift distance
1057 double denominator = xHit*xHit+yHit*yHit-rHit*rHit;
1058
1059 //double X1(0),Y1(0),X2(0),Y2(0),R(0);
1060 double X1 = 2*xHit/denominator;
1061 double Y1 = 2*yHit/denominator;
1062 double X2 = 2*xHit/denominator;
1063 double Y2 = 2*yHit/denominator;
1064 double R = 2*rHit/denominator;
1065
1066 while(x<xMax){
1067 double y1 = X1*cos(x) + Y1*sin(x) + R;
1068 double y2 = X2*cos(x) + Y2*sin(x) - R;
1069 double slope1 = -X1*sin(x) + Y1*cos(x);
1070 double slope2 = -X2*sin(x) + Y2*cos(x);
1071 double hitOnCircle1 = charge*slope1*y1;
1072 double hitOnCircle2 = charge*slope2*y2;
1073
1074 bool cut(true);
1075 cut = yMin<y1 && y1<yMax;
1076 //cut = cut && hitOnCircle1 <=0;
1077 if(cut){
1078 hitMap->Fill(x,y1);
1079 nPoint++;
1080 }
1081
1082 cut = yMin<y2 && y2<yMax;
1083 //cut = cut && hitOnCircle2 <= 0;
1084 if(cut){
1085 //if(hit.getHitType() == HoughHit::CGEMHIT)continue;// comment by llwang
1086 //int bin = hitMap->FindBin(x,y2);
1087 //if(hitMap->GetBinContent(bin)>0)continue;
1088 hitMap->Fill(x,y2);
1089 nPoint++;
1090 }
1091 x += dx;
1092 }
1093 }else{ // V-view hits
1094 //if(hit.getPairHit()==NULL)return nPoint;// FIXME
1095 //if(hit.getPairHit()->getHalfCircle()!=1)return nPoint;// FIXME
1096 int nTangency = trkCandi->calculateZ_S(hit);
1097 if(nTangency==0){
1098 //hit.setUse(-1);// why? FIXME
1099 }
1100 else
1101 {
1102 vector<HoughHit::S_Z> sz = hit->getSZ();
1103 vector<HoughHit::S_Z>::iterator iter = sz.begin();
1104 for(;iter!=sz.end();iter++)
1105 {
1106 double S = iter->first;
1107 double Z = iter->second;
1108 while(x<xMax)
1109 {
1110 double y = -S*x + Z;
1111 //y = S*cos(x) + Z*sin(x);
1112 bool cut(true);
1113 cut = yMin<y && y<yMax;
1114 if(cut)
1115 {
1116 hitMap->Fill(x,y);
1117 nPoint++;
1118 }
1119 x += dx;
1120 }
1121 }
1122 }
1123 //cout<<setw(8)<<""<<"nTangency="<<nTangency<<", nPointFilled="<<nPoint<<endl;
1124 }
1125 return nPoint;
1126}
1127
1128int HoughFinder::fillHistogram(vector<HoughHit*> &hitList, TH2D* hitMap, int charge, int vote, HoughTrack* trkCandi )
1129{
1130 bool nearStereoHits= false;
1131 if(trkCandi!=NULL) nearStereoHits = trkCandi->nearStereoHits();
1132
1133 int nHitsFilled = 0;
1134 m_nVClusterOnSZmap=0;
1135 m_VHoughHitListOnSZmap.clear();
1136 std::vector<HoughHit*>::iterator iter = hitList.begin();
1137 for(; iter!= hitList.end(); iter++)
1138 {
1139 int used = (*iter)->getUse();
1140 if(used==0) // too tight? FIXME
1141 {
1142 int nPoint = 0;
1143 //(*iter)->print();
1144 if(trkCandi!=NULL){
1145 //if((*iter)->getPairHit()==NULL) continue;// FIXME
1146 //if((*iter)->getPairHit()->getHalfCircle()!=1)continue;// FIXME
1147 if(!nearStereoHits&&(*iter)->getHitType()==HoughHit::MDCHIT&&(*iter)->getFlag()!=0) continue;// if no axial hits around, the stereo hits should not be filled
1148
1149 nPoint=fillHistogram((*iter),hitMap,trkCandi,vote);
1150 }
1151 else{
1152 //if((*iter)->getPairHit()==NULL) continue;// FIXME
1153 //if((*iter)->getPairHit()->getHalfCircle()!=1)continue;// FIXME
1154 nPoint=fillHistogram(*iter,hitMap,charge,vote);
1155 }
1156 if(nPoint>0) {
1157 nHitsFilled++;
1158 if(trkCandi!=NULL)
1159 {
1160 if((*iter)->getHitType()==HoughHit::CGEMHIT) m_nVClusterOnSZmap++;
1161 m_VHoughHitListOnSZmap.push_back(*iter);
1162 }
1163 }
1164 //cout<<nPoint<<" nPoint filled"<<(*iter)->print();
1165 }
1166 }
1167 return nHitsFilled;
1168}
1169
1170//////////////////////////////////////////////////---Hough Transform---//////////////////////////////////////////////////
1171/*
1172//Depth First Search Peak
1173int HoughFinder::findTrack(vector<HoughHit> &hitList, vector<HoughTrack*>& trackVector, double x, double y, double dx, double dy, int charge, int mapType, int step)
1174{
1175step++;
1176if(mapType==0){
1177m_nStep = m_nStep_xy;
1178m_xBin = m_xBin_xy;
1179m_yBin = m_yBin_xy;
1180m_xExtend = m_xExtend_xy;
1181m_yExtend = m_yExtend_xy;
1182m_nVote = m_nVote_xy;
1183m_nRMS = m_nRMS_xy;
1184m_xInclude = m_xInclude_xy;
1185m_yInclude = m_yInclude_xy;
1186}else{
1187m_nStep = m_nStep_sz;
1188m_xBin = m_xBin_sz;
1189m_yBin = m_yBin_sz;
1190m_xExtend = m_xExtend_sz;
1191m_yExtend = m_yExtend_sz;
1192m_nVote = m_nVote_sz;
1193m_nRMS = m_nRMS_sz;
1194m_xInclude = m_xInclude_sz;
1195m_yInclude = m_yInclude_sz;
1196}
1197
1198// --- build maps
1199map<int,TH2D*> hitMapList;
1200TH2D* houghMap = buildMap(hitList,hitMapList,x,y,dx,dy,charge,mapType,step);
1201//cout<<"hitMapList.size()+++"<<hitMapList.size()<<" "<<charge<<endl;
1202// --- find peaks
1203findPeak(hitList,hitMapList,houghMap,trackVector,charge,mapType,step);
1204// --- clear maps
1205clearMap(houghMap,hitMapList);
1206//cout<<"hitMapList.size()---"<<hitMapList.size()<<endl;
1207//cout<<endl<<endl;
1208return trackVector.size();
1209}
1210
1211
1212TH2D* HoughFinder::buildMap(vector<HoughHit> &hitList, map<int,TH2D*>& hitMapList, double x, double y, double dx, double dy, int charge, int mapType, int step)
1213{
1214int vote = m_nVote[step-1];
1215int xBin = m_xBin[step-1];
1216int yBin = m_yBin[step-1];
1217double xExtend = 0.5+m_xExtend[step-1];
1218double yExtend = 0.5+m_yExtend[step-1];
1219if(m_findPeakMethod==1){
1220vote = m_nVote[step-m_nStep-1];
1221xBin = m_xBin[step-m_nStep-1];
1222yBin = m_yBin[step-m_nStep-1];
1223xExtend = 0.5+m_xExtend[step-m_nStep-1];
1224yExtend = 0.5+m_yExtend[step-m_nStep-1];
1225}
1226double xMin = x-dx*xExtend;
1227double xMax = x+dx*xExtend;
1228double yMin = y-dy*yExtend;
1229double yMax = y+dy*yExtend;
1230stringstream ssname;
1231ssname<<"step"<<step;
1232string sname = ssname.str();
1233const char * name = sname.c_str();
1234TH2D* houghMap = new TH2D(name, name, xBin, xMin, xMax, yBin, yMin, yMax);
1235HitVector_Iterator hitIt = hitList.begin();
1236for(; hitIt != hitList.end();hitIt++){
1237//hitIt->print();
1238if(hitIt->getFlag()==1 && hitIt->getHitType() == HoughHit::CGEMHIT)continue;
1239if(mapType==0 && hitIt->getFlag() != 0)continue;
1240if(mapType!=0 && hitIt->getFlag() == 0)continue;
1241int hitID = hitIt->getHitID();
1242stringstream ssname;
1243ssname<<"step"<<step<<",hitID"<<hitID;
1244string sname = ssname.str();
1245const char * name = sname.c_str();
1246TH2D* hitMap = new TH2D(name, name, xBin, xMin, xMax, yBin, yMin, yMax);
1247int nPoint = fillHistogram((*hitIt),hitMap,charge,vote);
1248if(nPoint>0){
1249 houghMap->Add(hitMap);
1250 hitMapList[hitID] = hitMap;
1251}else delete hitMap;
1252}
1253return houghMap;
1254}
1255
1256int HoughFinder::findPeak(vector<HoughHit> &hitList, map<int,TH2D*>& hitMapList, TH2D* houghMap, vector<HoughTrack*>& trackVector, int charge, int mapType, int step)
1257{
1258 int trkID = trackVector.size();
1259 int binx(0),biny(0),binz(0);
1260 houghMap->GetMaximumBin(binx,biny,binz);
1261 int peakHeight = houghMap->GetBinContent(binx,biny);
1262 int nRMS = m_nRMS[step-1];
1263 if(m_findPeakMethod==1)nRMS = m_nRMS[step-m_nStep-1];
1264 double peakCut = mapDev(houghMap,nRMS);
1265 int nPeaks(0);
1266 int nRemove(0);
1267 while(peakHeight>peakCut){
1268 houghMap->GetMaximumBin(binx,biny,binz);
1269 double x = houghMap->GetXaxis()->GetBinCenter(binx);
1270 double y = houghMap->GetYaxis()->GetBinCenter(biny);
1271 double dx = houghMap->GetXaxis()->GetBinWidth(binx);
1272 double dy = houghMap->GetYaxis()->GetBinWidth(biny);
1273 //cout<<x<<" "<<y<<endl;
1274 centroid(houghMap,m_xInclude,m_yInclude,x,y);
1275 //cout<<x<<" "<<y<<endl;
1276 if(step<m_nStep){
1277 findTrack(hitList,trackVector,x,y,dx,dy,charge,mapType,step);
1278 nRemove = removeHitMap(hitMapList,houghMap,trackVector);
1279 if(nRemove==0)nRemove = removeHitMap(hitMapList,houghMap,binx,biny);
1280 }else{
1281 if(mapType == 0){
1282 HoughTrack* track = new HoughTrack(charge,x,y,dx,dy,trkID);
1283 //track->print();
1284 int nHot = track->findHot(hitList,mapType);
1285 if(nHot>=3){
1286 trackVector.push_back(track);
1287 nRemove = removeHitMap(hitMapList,houghMap,track);
1288 if(nRemove==0)nRemove = removeHitMap(hitMapList,houghMap,binx,biny);
1289 trkID++;
1290 }else{
1291 nRemove = removeHitMap(hitMapList,houghMap,binx,biny);
1292 }
1293
1294 }else if(trackVector.size()>0){
1295 HoughTrack* track = *(trackVector.begin());
1296 double tanl = track->tanl();
1297 double dz = track->dz();
1298 double dTanl = track->getDTanl();
1299 double dDz = track->getDDz();
1300 vector<HoughHit> hot;
1301 int nHot1 = track->findHot(hitList,hot,mapType);
1302 track->setTanl(x);
1303 track->setDz(y);
1304 track->setDTanl(dx);
1305 track->setDDz(dy);
1306 track->updateHelix();
1307 int nHot2 = track->findHot(hitList,hot,mapType);
1308 if(nHot1>nHot2){
1309 track->setTanl(tanl);
1310 track->setDz(dz);
1311 track->setDTanl(dTanl);
1312 track->setDDz(dDz);
1313 track->updateHelix();
1314 }
1315 nRemove = removeHitMap(hitMapList,houghMap,binx,biny);
1316 }
1317 }
1318 //double xKurtosis = houghMap->GetKurtosis(1);
1319 //double yKurtosis = houghMap->GetKurtosis(2);
1320 houghMap->GetMaximumBin(binx,biny,binz);
1321 peakHeight = houghMap->GetBinContent(binx,biny);
1322 peakCut = mapDev(houghMap,nRMS);
1323 nPeaks++;
1324 //if(mapType!=0 && nPeaks>0)break;
1325 if(nRemove==0)break;
1326 }
1327 return nPeaks;
1328}
1329
1330//remove map of hits that on the peak cell
1331int HoughFinder::removeHitMap(map<int,TH2D*>& hitMapList, TH2D* houghMap,int binx, int biny)
1332{
1333 bool debug(0);
1334 int nRemove(0);
1335 //if(debug){
1336 //cout<<endl;
1337 //for(map<int,TH2D*>::iterator iter = hitMapList.begin();iter != hitMapList.end();iter++){
1338 //cout<<"hit->"<<iter->first<<" ";
1339 //if(iter->second==NULL)cout<<"erased"<<endl;
1340 //else cout<<iter->second->GetBinContent(binx,biny)<<endl;
1341 //}
1342 //cout<<endl;
1343 //}
1344
1345 //int binx(0),biny(0),binz(0);
1346 //houghMap->GetMaximumBin(binx,biny,binz);
1347 map<int,TH2D*>::iterator iter = hitMapList.begin();
1348 for(;iter != hitMapList.end();iter++){
1349 if(debug)cout<<"hit->"<<iter->first<<" ";
1350 if(iter->second!=NULL){
1351 if(iter->second->GetBinContent(binx,biny)>0){
1352 houghMap->Add(iter->second,-1);
1353 delete iter->second;
1354 iter->second = NULL;
1355 //hitMapList.erase(iter);
1356 //hitMapList.erase(iter->first);
1357 nRemove++;
1358 if(debug)cout<<" erasing";
1359 }
1360 }
1361 else{
1362 if(debug)cout<<" erased";
1363 }
1364 if(debug)cout<<endl;
1365 }
1366
1367 //if(debug){
1368 //cout<<endl;
1369 //for(map<int,TH2D*>::iterator iter = hitMapList.begin();iter != hitMapList.end();iter++){
1370 //cout<<"hit->"<<iter->first<<" ";
1371 //if(iter->second==NULL)cout<<"erased"<<endl;
1372 //else cout<<iter->second->GetBinContent(binx,biny)<<endl;
1373 //}
1374 //cout<<endl;
1375 //}
1376
1377 return nRemove;
1378}
1379
1380//remove map of hits that on the track
1381int HoughFinder::removeHitMap(map<int,TH2D*>& hitMapList, TH2D* houghMap, HoughTrack* track)
1382{
1383 bool debug(1);
1384 int nRemove(0);
1385 //if(debug){
1386 //cout<<endl;
1387 //for(map<int,TH2D*>::iterator iter = hitMapList.begin();iter != hitMapList.end();iter++){
1388 //cout<<"hit->"<<iter->first<<" ";
1389 //if(iter->second==NULL)cout<<"erased"<<endl;
1390 //else{
1391 //int bin = iter->second->FindBin(track->getAngle(),track->getRho());
1392 //cout<<iter->second->GetBinContent(bin)<<endl;
1393 //}
1394 //}
1395 //cout<<endl;
1396 //}
1397
1398 vector<HoughHit>* hot = track->getHot();
1399 HitVector_Iterator hotIt = hot->begin();
1400 for(;hotIt!=hot->end();hotIt++){
1401 int hitID = hotIt->getHitID();
1402 if(debug)cout<<"hit->"<<hitID<<" ";
1403 map<int,TH2D*>::iterator iter = hitMapList.find(hitID);
1404 if(iter->second!=NULL){
1405 if(iter != hitMapList.end()){
1406 houghMap->Add(iter->second,-1);
1407 delete iter->second;
1408 iter->second = NULL;
1409 //hitMapList.erase(iter);
1410 //hitMapList.erase(iter->first);
1411 nRemove++;
1412 if(debug)cout<<"erasing"<<endl;
1413 }
1414 }else{
1415 if(debug)cout<<"erased"<<endl;
1416 }
1417 }
1418
1419 //if(debug){
1420 //cout<<endl;
1421 //for(map<int,TH2D*>::iterator iter = hitMapList.begin();iter != hitMapList.end();iter++){
1422 //cout<<"hit->"<<iter->first<<" ";
1423 //if(iter->second==NULL)cout<<"erased"<<endl;
1424 //else{
1425 //int bin = iter->second->FindBin(track->getAngle(),track->getRho());
1426 //cout<<iter->second->GetBinContent(bin)<<endl;
1427 //}
1428 //}
1429 //cout<<endl;
1430 //}
1431 return nRemove;
1432}
1433
1434//remove map of hits that on all tracks
1435int HoughFinder::removeHitMap(map<int,TH2D*>& hitMapList, TH2D* houghMap, vector<HoughTrack*>& trackVector)
1436{
1437 int nRemove(0);
1438 TrackVector_Iterator trkIter = trackVector.begin();
1439 for(;trkIter!=trackVector.end();trkIter++){
1440 if((*trkIter)->getFlag() == 1)continue;
1441 vector<HoughHit>* hot = (*trkIter)->getHot();
1442 HitVector_Iterator iter = hot->begin();
1443 for(;iter!=hot->end();iter++){
1444 int hitID = iter->getHitID();
1445 map<int,TH2D*>::iterator iter = hitMapList.find(hitID);
1446 if(iter != hitMapList.end()){
1447 houghMap->Add(iter->second,-1);
1448 delete iter->second;
1449 //iter->second = NULL;
1450 hitMapList.erase(iter);
1451 nRemove++;
1452 }
1453 }
1454 }
1455 //for(map<int,TH2D*>::iterator iter = hitMapList.begin();iter != hitMapList.end();iter++){
1456 //if(iter->second!=NULL)cout<<iter->first<<" "<<iter->second->GetBinContent(binx,biny)<<endl;
1457 //else cout<<iter->first<<" "<<" erase"<<endl;
1458 //}
1459 //cout<<endl;
1460 return nRemove;
1461}
1462
1463int HoughFinder::clearMap(TH2D* houghMap, map<int,TH2D*>& hitMapList)
1464{
1465 int nRemove(0);
1466 map<int,TH2D*>::iterator iter = hitMapList.begin();
1467 for(;iter != hitMapList.end();iter++){
1468 if(iter->second != NULL){
1469 delete iter->second;
1470 iter->second = NULL;
1471 //hitMapList.erase(iter);
1472 nRemove++;
1473 }
1474 }
1475 hitMapList.clear();
1476
1477 delete houghMap;
1478 houghMap = NULL;
1479
1480 return nRemove;
1481}
1482
1483
1484int HoughFinder::centroid(TH2D* houghMap, int xInclude, int yInclude, double &xc, double &yc)
1485{
1486 double X(0),Y(0),W(0);
1487 int binx(0),biny(0),binz(0);
1488 houghMap->GetMaximumBin(binx,biny,binz);
1489 int xMin = binx-xInclude>0?binx-xInclude:0;
1490 int xMax = binx+xInclude<houghMap->GetNbinsX()?binx+xInclude:houghMap->GetNbinsX();
1491 int yMin = biny-yInclude>0?biny-yInclude:0;
1492 int yMax = biny+yInclude<houghMap->GetNbinsY()?biny+yInclude:houghMap->GetNbinsY();
1493 //cout<<houghMap->GetNbinsX()<<" "<<houghMap->GetNbinsY()<<endl;
1494 for(int i=binx-xInclude;i<=binx+xInclude;i++){
1495 for(int j=biny-yInclude;j<=biny+yInclude;j++){
1496 double x = houghMap->GetXaxis()->GetBinCenter(i);
1497 double y = houghMap->GetYaxis()->GetBinCenter(j);
1498 int w = houghMap->GetBinContent(i,j);
1499 X += w*x;
1500 Y += w*y;
1501 W += w;
1502 }
1503 }
1504 if(W>0){
1505 xc = X/W;
1506 yc = Y/W;
1507 }
1508 return W;
1509}
1510
1511double HoughFinder::mapDev(TH2D* houghMap,double nRMS)
1512{
1513 int xBins = houghMap->GetXaxis()->GetNbins();
1514 int yBins = houghMap->GetYaxis()->GetNbins();
1515 int count_use=0;
1516 double sum=0;
1517 double sum2=0;
1518 for(int i=0;i<xBins;i++){
1519 for(int j=0;j<yBins;j++){
1520 int count=houghMap->GetBinContent(i+1,j+1);
1521 if(count!=0){
1522 count_use++;
1523 sum+=count;
1524 sum2+=count*count;
1525 }
1526 }
1527 }
1528 double aver(0),rms(0);
1529 if(count_use != 0){
1530 aver=sum/count_use;
1531 if(count_use==1) rms = sqrt(sum2/count_use-aver*aver);
1532 else rms = sqrt((sum2-count_use*aver*aver)/(count_use-1));
1533 }
1534 double cut = aver + nRMS*rms;
1535 return cut;
1536}
1537//*/
1538/*
1539//Breadth First Search Peak
1540int HoughFinder::findTrack(vector<HoughTrack>& trackVector, int charge, int mapType, int step)
1541{
1542step++;
1543vector<HoughTrack>& trkVector;
1544TrackVector_Iterator trkIter = trackVector.begin();
1545for(;trkIter!=trackVector.end();trkIter++){
1546int xBin = 10;
1547int yBin = 10;
1548double xPeak = trkIter->getAlpha();
1549double yPeak = trkIter->getRho();
1550double dx(0),dy(0);
1551if(mapType==0){
1552dx = trkIter->getDAngle();
1553dy = trkIter->getDRho();
1554}else{
1555dx = trkIter->getDTanl();
1556dy = trkIter->getDDz();
1557}
1558findTrack(trackVector,xPeak-dx,xPeak+dx,yPeak-dy,yPeak+dy,charge,mapType,m_nStep+step);
1559}
1560trackVector.swap(trkVector);
1561if(step<m_nStep)findTrack(trackVector);
1562}
1563
1564//Breadth First Search Peak
1565int HoughFinder::findTrack(vector<HoughTrack>& trackVector, int charge, int mapType, int step)
1566{
1567while(step<m_nStep){
1568step++;
1569vector<HoughTrack>& trkVector;
1570trackVector.swap(trkVector);
1571trackVector.clear();
1572TrackVector_Iterator trkIter = trkVector.begin();
1573for(;trkIter!=trkVector.end();trkIter++){
1574int xBin = 10;
1575int yBin = 10;
1576double xPeak = trkIter->getAlpha();
1577double yPeak = trkIter->getRho();
1578double dx(0),dy(0);
1579if(mapType==0){
1580dx = trkIter->getDAngle();
1581dy = trkIter->getDRho();
1582}else{
1583dx = trkIter->getDTanl();
1584dy = trkIter->getDDz();
1585}
1586findTrack(trackVector,xPeak-dx,xPeak+dx,yPeak-dy,yPeak+dy,charge,mapType,m_nStep+step);
1587}
1588}
1589//trackVector.swap(trkVector);
1590if(step<m_nStep)findTrack(trackVector);
1591}
1592//*/
1593
1595{
1596 int nHot1 = trk1.getHotList().size();
1597 int nHot2 = trk2.getHotList().size();
1598 return nHot1>nHot2;
1599 //return trk1.getHot().size() > trk2.getHot().size();
1600}
1601
1602//check track by hots, remove the shorter track with too many shared hits
1603// --- v1 ---
1604/*
1605 int HoughFinder::checkHot(vector<HoughTrack>& trackVector)
1606 {
1607 int nDelete(0);
1608 std::sort(trackVector.begin(),trackVector.end(),moreHot);// sort track candidates from more hits to less
1609 for(vector<HoughTrack>::iterator trkIT1 = trackVector.begin(); trkIT1!=trackVector.end(); trkIT1++){
1610 if((trkIT1)->getFlag() == 1)continue;
1611 vector<HoughHit>* hot1 = (trkIT1)->getHot();
1612 trkIT1->dropRedundentCgemXHits();
1613//cout<<"hit size "<<hot1->size()<<endl;
1614if(hot1->size()<3){
1615(trkIT1)->setFlag(1);
1616trkIT1->releaseSelHits();
1617continue;
1618}
1619
1620for(vector<HoughTrack>::iterator trkIT2 = trkIT1+1; trkIT2!=trackVector.end();trkIT2++){
1621if((trkIT2)->getFlag() == 1)continue;
1622vector<HoughHit>* hot2 = (trkIT2)->getHot();
1623if(hot2->size()<3){
1624(trkIT2)->setFlag(1);
1625trkIT2->releaseSelHits();
1626continue;
1627}
1628
1629int shareHit(0);
1630for(HitVector_Iterator hitIt1 = hot1->begin(); hitIt1 != hot1->end(); hitIt1++){
1631for(HitVector_Iterator hitIt2 = hot2->begin(); hitIt2 != hot2->end(); hitIt2++){
1632//cout<<"id2, id1 = "<<hitIt2->getHitID()<<", "<<hitIt1->getHitID()<<endl;
1633if(hitIt2->getHitID()==hitIt1->getHitID())shareHit++;
1634}
1635}
1636//cout<<"shareHit = "<<shareHit<<endl;
1637if(shareHit>m_shareHitRate*hot2->size()){
1638//delete *trkIT2;
1639//trackVector.erase(trkIT2);
1640//trkIT2--;
1641(trkIT2)->setFlag(1);
1642trkIT2->releaseSelHits();
1643nDelete++;
1644cout<<"too many shared hits ("<<shareHit<<"/"<<hot2->size()
1645<<") in track "<<(trkIT2)->getTrkID()
1646<<" with track "<<trkIT1->getTrkID()<<endl;
1647}
1648}
1649}
1650return nDelete;
1651}
1652//*/
1653
1654// --- v2 ---
1655int HoughFinder::checkHot(vector<HoughTrack>& trackVector)
1656{
1657 //m_debug=true;
1658 int nDelete(0);
1659 if(trackVector.size()==0)return 0;
1660 std::sort(trackVector.begin(),trackVector.end(),moreHot);// sort track candidates from more hits to less
1661
1662 vector<HoughTrack>::iterator trkIT1 = trackVector.end();
1663 //vector<HoughTrack>::iterator trkIT1 = trackVector.rbegin();
1664 bool loop = true;
1665
1666 while(loop)
1667 {
1668 trkIT1--;
1669 if(trkIT1==trackVector.begin()) loop=false;
1670 if((trkIT1)->getFlag() == 1) continue;
1671 //trkIT1->dropRedundentCgemXHits();
1672 //cout<<"hit size "<<hot1->size()<<endl;
1673 int nHits = trkIT1->getVecHitPnt().size();
1674 if(nHits<3){
1675 (trkIT1)->setFlag(1);
1676 trkIT1->releaseSelHits();
1677 if(m_debug==1) {
1678 cout<<"too less hits ("<<nHits<<") in track "<<(trkIT1)->getTrkID()<<endl;
1679 }
1680 continue;
1681 }
1682 int nShared = trkIT1->getNHitsShared();
1683
1684 //cout<<"shareHit = "<<shareHit<<endl;
1685 if(nShared>m_shareHitRate*nHits){
1686 trkIT1->setFlag(1);
1687 trkIT1->releaseSelHits();
1688 nDelete++;
1689 if(m_debug==1) {
1690 cout<<"too many shared hits ("<<nShared<<"/"<<nHits
1691 <<") in track "<<(trkIT1)->getTrkID()
1692 <<endl;
1693 }
1694 }
1695 }
1696 //m_debug=false;
1697 return nDelete;
1698}
1699
1700int HoughFinder::checkTrack(vector<HoughTrack>& trackVector)
1701{
1702 int nDelete(0);
1703 double dDr(999);
1704 double dPhi0(999);
1705 double dKappa(999);
1706 double dDz(999);
1707 double dTanl(999);
1708
1709 //m_debug=true;
1710
1711 std::sort(trackVector.begin(),trackVector.end(),moreHot);// sort track candidates from more hits to less
1712 for(vector<HoughTrack>::iterator trkIT1 = trackVector.begin(); trkIT1!=trackVector.end(); trkIT1++){
1713 if((trkIT1)->getFlag() == 1)continue;
1714 int charge = (trkIT1)->getCharge();
1715 double dr = (trkIT1)->dr();
1716 double phi0 = (trkIT1)->phi0();
1717 double kappa = (trkIT1)->kappa();
1718 double dz = (trkIT1)->dz();
1719 double tanl = (trkIT1)->tanl();
1720 for(vector<HoughTrack>::iterator trkIT2 = trkIT1+1; trkIT2!=trackVector.end();trkIT2++){
1721 if((trkIT2)->getFlag() == 1)continue;
1722 bool sameTrack(false);
1723 dDr = fabs(dr - (trkIT2)->dr());
1724 dPhi0 = fabs(phi0 - (trkIT2)->phi0());
1725 if((trkIT2)->getCharge() == charge){
1726 dKappa = fabs(kappa - (trkIT2)->kappa());
1727 dTanl = fabs(tanl - (trkIT2)->tanl());
1728 }else{
1729 dKappa = fabs(fabs(kappa) - fabs((trkIT2)->kappa()));
1730 dTanl = fabs(fabs(tanl) - fabs((trkIT2)->tanl()));
1731 }
1732 double r = fabs(dz)<fabs((trkIT2)->dz())?(trkIT1)->radius():(trkIT2)->radius();
1733 double k = dz<fabs((trkIT2)->dz())?tanl:(trkIT2)->tanl();
1734 dDz = fabs(dz - (trkIT2)->dz());
1735 int nCircle = fabs(dDz)/(2*M_PI*r*k);
1736 dDz = fabs(dDz - nCircle*(2*M_PI*r*k));
1737 if(dDz>M_PI*r*k)dDz = fabs(dDz - 2*M_PI*r*k);
1738 if(dPhi0<m_phi0Cut&&dKappa<m_kappaCut&&dTanl<m_tanlCut) sameTrack=true;
1739 //sameTrack = sameTrack&&(dDr<m_drCut);//FIXME
1740 //sameTrack = sameTrack&&(dPhi0<m_phi0Cut);//FIXME
1741 //sameTrack = sameTrack&&(dKappa<m_kappaCut);//FIXME
1742 //sameTrack = sameTrack&&(dDz<m_dzCut);//FIXME
1743 //sameTrack = sameTrack&&(dTanl<m_tanlCut);//FIXME
1744 if(sameTrack){
1745 //delete *trkIT2;
1746 //trackVector.erase(trkIT2);
1747 //trkIT2--;
1748 (trkIT2)->setFlag(1);
1749 if(m_debug==5) {
1750 cout<<"dDr, dPhi0, dKappa, dDz, dTanl "
1751 <<setw(10)<<dDr
1752 <<setw(10)<<dPhi0
1753 <<setw(10)<<dKappa
1754 <<setw(10)<<dDz
1755 <<setw(10)<<dTanl
1756 <<endl;
1757 cout<<"similar track "<<trkIT2->getTrkID()<<" is removed from hough track list"<<endl;
1758 }
1759
1760 // --- associate the hits of track 2 to track 1 if within pi/2 // to-do
1761 nDelete++;
1762 }
1763 }
1764 }
1765 if(m_debug==5) cout<<"checkTrack(): "<<nDelete<<" similar tracks are removed from hough track list"<<endl;
1766 //m_debug=false;
1767 return nDelete;
1768}
1769
1770/*
1771//fit tracks on xy plane, calculate S and Z of hits as well as add them to tracks, then calculate tanl and dz by Hough Transform and fit tracks again
1772int HoughFinder::completeTrack(vector<HoughTrack*>& trackVector)
1773{
1774int nTrk(0);
1775for(TrackVector_Iterator trackIT = trackVector.begin();trackIT!=trackVector.end();trackIT++){
1776if((*trackIT)->getFlag() == 1)continue;
1777
1778//cout<<"begin circlr fit "<<endl;
1779TrkErrCode trkErrCode = (*trackIT)->fitCircle(m_mdcDetector,m_trkContextEv,m_bunchT0);
1780//cout<<"finish circlr fit "<<endl;
1781if(trkErrCode.failure()){
1782(*trackIT)->setFlag(1);
1783continue;
1784}
1785//cout<<"finish circlr fit "<<endl;
1786
1787vector<HoughHit> stereoHot;
1788for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++){
1789HoughHit hit(*hitIt);
1790if((*trackIT)->calculateZ_S(hit)>0)stereoHot.push_back(hit);
1791}
1792if(stereoHot.size()<2){//FIXME
1793(*trackIT)->setFlag(1);
1794continue;
1795}
1796//cout<<"finish stereo hot finding "<<endl;
1797
1798double tanl = 0;
1799double dz = 0;
1800//double dTanl = 0.93/sqrt(1-0.93*0.93);
1801double dTanl = 3.0;
1802double dDz = 50.0;
1803int mapType = 1;
1804int step = 0;
1805int charge = 0;
1806vector<HoughTrack*> trkVector;
1807trkVector.push_back(*trackIT);
1808//cout<<"before trk finding "<<endl;
1809findTrack(stereoHot,trkVector,tanl,dz,dTanl,dDz,charge,mapType,step);
1810//cout<<"end trk finding "<<endl;
1811TrackVector_Iterator trkIT = trkVector.begin();
1812HoughTrack* trk = (*trkIT);
1813int nHot = trk->findHot(stereoHot,mapType);
1814if(nHot<2){//FIXME
1815(*trackIT)->setFlag(1);
1816continue;
1817}
1818trkErrCode = trk->fitHelix(m_mdcDetector,m_trkContextEv,m_bunchT0,m_mdcHitCol);
1819if(trkErrCode.failure()){
1820(*trackIT)->setFlag(1);
1821continue;
1822}
1823nTrk++;
1824}
1825return nTrk;
1826}
1827//*/
1828StatusCode HoughFinder::registerTrack(RecMdcTrackCol*& recMdcTrackCol ,RecMdcHitCol*& recMdcHitCol)
1829{
1830 MsgStream log(msgSvc(), name());
1831 StatusCode sc;
1832 IDataProviderSvc* eventSvc = NULL;
1833 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
1834 if (eventSvc) {
1835 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
1836 } else {
1837 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
1838 return StatusCode::FAILURE;
1839 //return StatusCode::SUCCESS;
1840 }
1841 IDataManagerSvc *dataManSvc = dynamic_cast<IDataManagerSvc*>(eventSvc);;
1842
1843
1844 // --- register RecMdcTrack
1845 recMdcTrackCol = new RecMdcTrackCol;
1846 DataObject *aRecMdcTrackCol;
1847 eventSvc->findObject("/Event/Recon/RecMdcTrackCol",aRecMdcTrackCol);
1848 if(aRecMdcTrackCol != NULL) {
1849 dataManSvc->clearSubTree("/Event/Recon/RecMdcTrackCol");
1850 eventSvc->unregisterObject("/Event/Recon/RecMdcTrackCol");
1851 }
1852
1853 sc = eventSvc->registerObject("/Event/Recon/RecMdcTrackCol", recMdcTrackCol);
1854 if(sc.isFailure()) {
1855 log << MSG::FATAL << " Could not register RecMdcTrack collection" <<endreq;
1856 return StatusCode::FAILURE;
1857 }
1858 log << MSG::INFO << "RecMdcTrackCol registered successfully!" <<endreq;
1859
1860
1861
1862 recMdcHitCol = new RecMdcHitCol;
1863 DataObject *aRecMdcHitCol;
1864 eventSvc->findObject("/Event/Recon/RecMdcHitCol",aRecMdcHitCol);
1865 if(aRecMdcHitCol != NULL) {
1866 dataManSvc->clearSubTree("/Event/Recon/RecMdcHitCol");
1867 eventSvc->unregisterObject("/Event/Recon/RecMdcHitCol");
1868 }
1869
1870 sc = eventSvc->registerObject("/Event/Recon/RecMdcHitCol", recMdcHitCol);
1871 if(sc.isFailure()) {
1872 log << MSG::FATAL << " Could not register RecMdcHit collection" <<endreq;
1873 return StatusCode::FAILURE;
1874 }
1875 log << MSG::INFO << "RecMdcHitCol registered successfully!" <<endreq;
1876
1877
1878 return StatusCode::SUCCESS;
1879}//end of stroeTracks
1880
1881int HoughFinder::storeTrack(vector<HoughTrack>& trackVector, RecMdcTrackCol*& recMdcTrackCol ,RecMdcHitCol*& recMdcHitCol)
1882{
1883 MdcTrackParams mdcTrackParams;
1884 //mdcTrackParams.lPrint=8;
1885 mdcTrackParams.lRemoveInActive=1;
1886 mdcTrackParams.maxGapLength=99;
1887 mdcTrackParams.nHitDeleted=99;
1888 MdcTrackList mdcTrackList(mdcTrackParams);
1889 mdcTrackList.setNoInner(true);
1890 vector<MdcTrack*> mdcTrackVector;
1891 for(vector<HoughTrack>::iterator trkIT = trackVector.begin();trkIT!=trackVector.end();trkIT++){
1892 if((trkIT)->getFlag() == 1)continue;
1893 if((trkIT)->getFlag() == -1)continue;
1894 if((trkIT)->getFlag() == -2)continue;
1895 //(trkIT)->sortHot();
1896 MdcTrack* mdcTrack = new MdcTrack((trkIT)->getTrkRecoTrk());
1897 mdcTrackList.append(mdcTrack);
1898 mdcTrackVector.push_back(mdcTrack);
1899 }
1900 int nDeleted(0);
1901 mdcTrackList.setNoInner(true);
1902 if(m_checkHits)nDeleted = mdcTrackList.arbitrateHits();
1903 if(nDeleted>0)cout<<"nDeleted "<<nDeleted<<endl;
1904
1905 int trkID=0;
1906 for(int l=0;l<mdcTrackList.length();l++){
1907 mdcTrackList[l]->storeTrack(trkID,recMdcTrackCol,recMdcHitCol,4);
1908 trkID++;
1909 }
1910
1911 vector<MdcTrack*>::iterator iter = mdcTrackVector.begin();
1912 for(;iter!=mdcTrackVector.end();iter++){
1913 if(m_clearTrack)delete *iter;
1914 }
1915 return trkID;
1916}
1917
1918bool sortCluster(const RecCgemCluster* clusterA , const RecCgemCluster* clusterB){
1919 return clusterA->getlayerid()<clusterB->getlayerid();
1920}
1921
1922int HoughFinder::storeRecTracks(RecMdcTrackCol* trackList, RecMdcHitCol* hitList, vector<HoughTrack>& trackVector)
1923{
1924 bool debug=false; //debug=true;
1925 int trackId(0);
1926 int tkStat =4;
1927 if(debug) cout<<"N Rectrack: "<<trackVector.size()<<endl;
1928 sort(trackVector.begin(),trackVector.end(),largerPt);
1929
1930 for(vector<HoughTrack>::iterator trkIT = trackVector.begin(); trkIT!=trackVector.end(); trkIT++)
1931 {
1932
1933 if(debug) cout<<"trk flag: "<<(trkIT)->getFlag()<<endl;
1934
1935 //if((trkIT)->getFlag() == 1)continue;
1936 //if((trkIT)->getFlag() == -1)continue;
1937 //if((trkIT)->getFlag() == -2)continue;
1938 if((trkIT)->getFlag()!=0) continue;
1939
1940 if(debug)
1941 {
1942 cout<<"the following track will be saved: "<<endl;
1943 trkIT->print();
1944 }
1945
1946 //new a Rec. Track MdcTrack
1947 RecMdcTrack* recMdcTrack = new RecMdcTrack();
1948
1949 recMdcTrack->setTrackId(trackId);
1950
1951 double helixPar[5];
1952 helixPar[0]=trkIT->getDr();
1953 helixPar[1]=trkIT->getPhi0();
1954 helixPar[2]=trkIT->getKappa();
1955 helixPar[3]=trkIT->getDz();
1956 helixPar[4]=trkIT->getTanl();//helixPar[4]+=0.1;
1957 recMdcTrack->setHelix(helixPar);
1958
1959 int q = trkIT->getCharge();
1960 double pxy = trkIT->pt();
1961 double px = trkIT->momentum(0).x();
1962 double py = trkIT->momentum(0).y();
1963 double pz = trkIT->momentum(0).z();
1964 double p = trkIT->momentum(0).mag();
1965 double theta = trkIT->direction(0).theta();
1966 double phi = trkIT->direction(0).phi();
1967 HepPoint3D poca = trkIT->x(0);
1968 HepPoint3D pivot = trkIT->pivot();
1969 double r = poca.perp();
1970 HepSymMatrix Ea = trkIT->Ea();
1971 //cout<<"Ea="<<Ea<<endl;
1972 double errorMat[15];
1973 int k = 0;
1974 for (int ie = 0 ; ie < 5 ; ie ++){
1975 for (int je = ie ; je < 5 ; je ++){
1976 errorMat[k] = Ea[ie][je];
1977 k++;
1978 }
1979 }
1980 // ---> a Helix for DotsHelixFitter
1981 HepVector a(5,0);
1982 a(1) =trkIT->getDr();
1983 a(2) =trkIT->getPhi0();
1984 a(3) =trkIT->getKappa();
1985 a(4) =trkIT->getDz();
1986 a(5) =trkIT->getTanl();
1987 KalmanFit::Helix aHelix(pivot,a,Ea); // <-- a Helix for DotsHelixFitter ---
1988 //myDotsHelixFitter.setInitialHelix(aHelix);// set a Helix for DotsHelixFitter
1989 double chisq = trkIT->getChi2();
1990 recMdcTrack->setCharge(q);
1991 recMdcTrack->setPxy(pxy);
1992 recMdcTrack->setPx(px);
1993 recMdcTrack->setPy(py);
1994 recMdcTrack->setPz(pz);
1995 recMdcTrack->setP(p);
1996 recMdcTrack->setTheta(theta);
1997 recMdcTrack->setPhi(phi);
1998 recMdcTrack->setPoca(poca);
1999 recMdcTrack->setX(poca.x());//poca
2000 recMdcTrack->setY(poca.y());
2001 recMdcTrack->setZ(poca.z());
2002 recMdcTrack->setR(sqrt(poca.x()*poca.x() + poca.y()*poca.y()));
2003 HepPoint3D apivot(0.,0.,0.);
2004 recMdcTrack->setPivot(apivot);
2005 recMdcTrack->setVX0(0.);//pivot
2006 recMdcTrack->setVY0(0.);
2007 recMdcTrack->setVZ0(0.);
2008 recMdcTrack->setError(errorMat);
2009 recMdcTrack->setError(Ea);
2010 recMdcTrack->setChi2(chisq);
2011 recMdcTrack->setStat(tkStat);
2012
2013 //-----------hit list-------------
2014 int hitId = 0;
2015 HitRefVec hitRefVec;
2016 ClusterRefVec clusterRefVec;
2017 //vector<int> vecHits;
2018 map<int,int> clusterFitStat;
2019 //int maxLayer = 0;
2020 int maxLayerId = -1;
2021 int minLayerId = 43;
2022 double fiTerm = 999.;
2023 HoughHit* fiTermHot = NULL;
2024
2025 //vector<HoughHit*> hotList = trkIT->getVecHitPnt();
2026 vector<HoughHit*> hotList = trkIT->getHotList(2);
2027 for(vector<HoughHit*>::iterator hotIt = hotList.begin(); hotIt != hotList.end();hotIt++)
2028 {
2029 //cout<<"handle hit "<<hitId<<endl;
2030 HoughHit* hot(*hotIt);
2031 //int layer = (**hotIt).getLayer();
2032 //int wire = (**hotIt).getWire();
2033 //cout<<"("<<setw(2)<<layer<<","<<setw(3)<<wire<<") ";
2034
2035 /*
2036 if(hot->getHitType()==HoughHit::MDCHIT)
2037 {
2038 //if(hot->getUse()!=1) continue;
2039 //cout<<"create a new RecMdcHit"<<endl;
2040
2041 // --- make a RecMdcHit from digi, aHelix using DotsHelixFitter
2042 RecMdcHit* recMdcHit = new RecMdcHit(myDotsHelixFitter.makeRecMdcHit(hot->getDigi(), aHelix));
2043 recMdcHit->setId(hitId);
2044 recMdcHit->setTrkId(trackId);
2045
2046 //
2047 // --> make a RecMdcHit from a HoughHit (parameters from Hough)
2048 RecMdcHit* recMdcHit = new RecMdcHit;
2049 recMdcHit->setId(hitId);
2050 recMdcHit->setTrkId(trackId);
2051 HepPoint3D hitPoint = hot->getHitPosition();
2052 double dPhi = trkIT->dPhi(hitPoint);
2053 HepPoint3D position = trkIT->x(dPhi);
2054 Hep3Vector direction = trkIT->direction(dPhi);
2055 //cout<<"get 1"<<endl;
2056
2057 double ddl = -1*hot->getDriftDist();
2058 double ddr = hot->getDriftDist();
2059 //double erddl = hot->hitSigma();
2060 //double erddr = hot->hitSigma();
2061 double pChisq = hot->getResidual()*hot->getResidual();//FIXME
2062 int lr = 0;
2063 int stat = hot->getUse();
2064 stat = 1; // llwang
2065 //cout<<"hit stat = "<<stat<<endl;
2066 //cout<<"get 2"<<endl;
2067 Identifier mdcId = hot->getDigi()->identify();
2068 //cout<<"get 2.1"<<endl;
2069 double tdc = hot->getDigi()->getTimeChannel();
2070 //cout<<"get 2.2"<<endl;
2071 double adc = hot->getDigi()->getChargeChannel();
2072 //cout<<"get 2.3"<<endl;
2073 double driftT = hot->driftTime();
2074 //cout<<"get 2.4"<<endl;
2075 double doca = hot->getDriftDist() +hot->getResidual();
2076 //cout<<"get 2.5"<<endl;
2077 double entra = direction.phi()-position.phi();//FIXME
2078 //cout<<"get 2.6"<<endl;
2079 while(entra<-0.5*M_PI)entra+= M_PI;
2080 while(entra> 0.5*M_PI)entra -= M_PI;
2081 //cout<<"get 3"<<endl;
2082 double zhit = hitPoint.z();
2083 double fltLen = trkIT->flightLength(hitPoint);
2084 //cout<<"after get "<<hitId<<endl;
2085
2086 recMdcHit->setDriftDistLeft(ddl);
2087 recMdcHit->setDriftDistRight(ddr);
2088 //recMdcHit->setErrDriftDistLeft(erddl);
2089 //recMdcHit->setErrDriftDistRight(erddr);
2090 recMdcHit->setChisqAdd(pChisq);
2091 recMdcHit->setFlagLR(lr);
2092 recMdcHit->setStat(stat);
2093 recMdcHit->setMdcId(mdcId);
2094 recMdcHit->setTdc(tdc);
2095 recMdcHit->setAdc(adc);
2096 recMdcHit->setDriftT(driftT);
2097 recMdcHit->setDoca(doca);
2098 recMdcHit->setEntra(entra);
2099 recMdcHit->setZhit(zhit);
2100 recMdcHit->setFltLen(fltLen);
2101 //cout<<"after set "<<hitId<<endl;
2102 // <--- make a RecMdcHit from a HoughHit
2103
2104 hitList->push_back(recMdcHit);
2105 SmartRef<RecMdcHit> refHit(recMdcHit);
2106 hitRefVec.push_back(refHit);
2107
2108 if(hot->getLayer()>maxLayerId){
2109 maxLayerId = hot->getLayer();
2110 fiTermHot = hot;
2111 }
2112 if(hot->getLayer()<minLayerId){
2113 minLayerId = hot->getLayer();
2114 }
2115 //if(hot->getUse()==1){
2116 recMdcHit->setStat(1);
2117 //}else{
2118 // recMdcHit->setStat(0);
2119 //}
2120 //cout<<"finish a DC hit "<<hitId<<endl;
2121 hitId++;
2122 }*/
2123 if(hot->getHitType()==HoughHit::CGEMHIT)
2124 {
2125 //hot->print();
2126 //cout<<endl;
2127 const RecCgemCluster* recCgemCluster = hot->getCgemCluster();
2128 int clusterid = hot->getCgemCluster()->getclusterid();
2129 //int stat = hot->getUse();
2130 int stat = 1;
2131 clusterFitStat[clusterid] = stat;
2132 clusterRefVec.push_back(recCgemCluster);
2133 if(debug) cout<<" cluster "<<clusterid<<" kept! "<<endl;
2134 if(hot->getLayer()>maxLayerId)
2135 {
2136 maxLayerId = hot->getLayer();
2137 fiTermHot = hot;
2138 }
2139 if(hot->getLayer()<minLayerId)
2140 {
2141 minLayerId = hot->getLayer();
2142 }
2143 }
2144 }// loop hotList (vector<HoughHit*>) of a hough track
2145
2146 // --- loop RecMdcHitVec in Hough track
2147 double fltLen = -1;
2148 vector<RecMdcHit>* RecMdcHitVecPnt = trkIT->getRecMdcHitVec();
2149 int nMdcHits=RecMdcHitVecPnt->size();
2150 int nMdcHitsKept=0;
2151 vector<RecMdcHit>::iterator iter_recMdcHit = RecMdcHitVecPnt->begin();
2152 for(; iter_recMdcHit!=RecMdcHitVecPnt->end(); iter_recMdcHit++)
2153 {
2154 RecMdcHit* recMdcHit = new RecMdcHit(*iter_recMdcHit);
2155 if(recMdcHit->getChisqAdd()>m_chi2CutHits) // skip hit with chi2>m_chi2CutHits
2156 {
2157 //cout<<"skip hit with chi2="<<recMdcHit->getChisqAdd()<<endl;
2158 delete recMdcHit;
2159 continue;
2160 }
2161 recMdcHit->setId(hitId);
2162 recMdcHit->setTrkId(trackId);
2163 recMdcHit->setStat(1);
2164 hitList->push_back(recMdcHit);
2165 SmartRef<RecMdcHit> refHit(recMdcHit);
2166 hitRefVec.push_back(refHit);
2167 nMdcHitsKept++;
2168
2169 Identifier mdcid = recMdcHit->getMdcId();
2170 int layer = MdcID::layer(mdcid);
2171 int wire = MdcID::wire(mdcid);
2172 if(debug) cout<<" hit at layer "<<layer<<" wire "<<wire<<" kept! "<<endl;
2173 if(layer>maxLayerId)
2174 {
2175 maxLayerId = layer;
2176 fltLen=recMdcHit->getFltLen();
2177 //fiTermHot = hot;
2178 }
2179 if(layer<minLayerId)
2180 {
2181 minLayerId = layer;
2182 }
2183 hitId++;
2184 }
2185 if(debug) cout<<"track "<<trackId<<", "<<nMdcHitsKept<<"/"<<nMdcHits<<" hits kept"<<endl;
2186
2187 //fi terminal angle
2188 if (fiTermHot!=NULL){
2189 //fiTerm=(1./sqrt(1.+tanDip*tanDip))*fiTermHot->fltLen()*helix.omega();
2190 HepPoint3D point = fiTermHot->getHitPosition();
2191 fiTerm = trkIT->flightArc(point)/trkIT->radius();
2192 }
2193 if(fltLen>0) fiTerm=-fltLen*sin(theta)/trkIT->radius();
2194 recMdcTrack->setFiTerm(fiTerm);
2195
2196 // --- setN* functions called in setVec* functions
2197 recMdcTrack->setVecHits(hitRefVec);
2198 std::sort(clusterRefVec.begin(),clusterRefVec.end(),sortCluster);
2199 recMdcTrack->setVecClusters(clusterRefVec,clusterFitStat);
2200 trackList->push_back(recMdcTrack);
2201 trackId++;
2202 }// loop HoughTrack list
2203 return trackList->size();
2204
2205}
2206
2207int HoughFinder::storeTracks(RecMdcTrackCol* trackList, RecMdcHitCol* hitList, vector<HoughTrack>& trackVector){
2208 bool debug=false; //debug=true;
2209 int trackId(0);
2210 int tkStat =4;
2211 if(debug) cout<<"N Rectrack: "<<trackVector.size()<<endl;
2212 sort(trackVector.begin(),trackVector.end(),largerPt);
2213
2214 for(vector<HoughTrack>::iterator trkIT = trackVector.begin();trkIT!=trackVector.end();trkIT++){
2215 if(debug) cout<<"trk flag: "<<(trkIT)->getFlag()<<endl;
2216 if((trkIT)->getFlag() == 1)continue;
2217 if((trkIT)->getFlag() == -1)continue;
2218 if((trkIT)->getFlag() == -2)continue;
2219 if(trkIT->getTrkRecoTrk()==NULL)
2220 {
2221 if(debug) cout<<"trk getTrkRecoTrk NULL!"<<endl;
2222 continue;
2223 }
2224 //get the results of the fit to this track
2225 const TrkFit* fitresult = trkIT->getTrkRecoTrk()->fitResult();
2226 //check the fit worked
2227 if (fitresult == 0)
2228 {
2229 if(debug) cout<<"no fit result!"<<endl;
2230 continue;
2231 }
2232 if(debug)
2233 {
2234 cout<<"the following track will be saved: "<<endl;
2235 trkIT->print();
2236 }
2237 if(printFlag)trkIT->print();
2238 if(printFlag)trkIT->printHot();
2239 //cout<<endl;
2240
2241 //new a Rec. Track MdcTrack
2242 RecMdcTrack* recMdcTrack = new RecMdcTrack();
2243 const TrkHitList* aList = trkIT->getTrkRecoTrk()->hits();
2244 //some track info
2245 const BField& theField = trkIT->getTrkRecoTrk()->bField();
2246 double Bz = theField.bFieldZ();
2247 //Fit info
2248 int hitId = 0;
2249 int nHits=0;
2250 int nSt=0;
2251 //int nAct=0; int nSeg=0;
2252 //int maxlay = 0; int minlay = 43; int seg[11];/* 11 slayer */ int segme;
2253 //****************************
2254 //* active flag open this
2255 //****************************
2256 //* if (allHit>0){
2257 //* nHits = aList->nHit();//add inActive hit also
2258 //* }else{
2259 //* nHits = fitresult->nMdc();// = nActive()
2260 //* }
2261 //****************************
2262 //for 5.1.0 use all hits
2263 nHits = aList->nHit();
2264 //****************************
2265 // use active only
2266 // nHits = fitresult->nMdc();// = nActive()
2267 //****************************
2268
2269 int q = fitresult->charge();
2270 double chisq = fitresult->chisq();
2271 int nDof = fitresult->nDof();
2272
2273 //if(nHits-nDof!=5) cout<<"HoughFinder::storeTracks: nHits-nDof!=5, nHits="<<nHits<<" , nDof="<<nDof<<", chi2="<<chisq<<" , evt="<<m_event<<endl;
2274
2275 //track parameters at closest approach to beamline
2276 double fltLenPoca = 0.0;
2277 TrkExchangePar helix = fitresult->helix(fltLenPoca);
2278 //std::cout<< __FILE__ << " phi0 " << helix.phi0() << " omega " <<helix.omega()<<std::endl;
2279 double phi0 = helix.phi0();
2280 double tanDip = helix.tanDip();
2281 //double z0 = helix.z0();
2282 double d0 = helix.d0();
2283 //momenta and position
2284 //CLHEP::Hep3Vector mom = fitresult->momentum(fltLenPoca);
2285 HepPoint3D poca = fitresult->position(fltLenPoca);
2286
2287 double helixPar[5];
2288 //dro =-d0
2289 helixPar[0] = -d0;
2290 //phi0 = phi0 - pi/2 [0,2pi)
2291 double tphi0 = phi0 - Constants::pi/2.;
2292 if (tphi0 < 0. ) tphi0 += Constants::pi * 2.;
2293 helixPar[1] = tphi0;
2294 //kappa = q/pxy
2295 double pxy = fitresult->pt();
2296 if (pxy == 0.) helixPar[2] = 9999.;
2297 else helixPar[2] = q/fabs(pxy);
2298 if(pxy>9999.) helixPar[2] = 0.00001;
2299 //dz = z0
2300 helixPar[3] = helix.z0();
2301 //tanl
2302 helixPar[4] = tanDip;
2303 //error
2304 //V(Y)=S * V(X) * ST , mS = S , mVy = V(Y) , helix.covariance() = V(X)
2305 HepSymMatrix mS(helix.params().num_row(),0);
2306 mS[0][0]=-1.;//dr0=-d0
2307 mS[1][1]=1.;
2308 mS[2][2]=-333.567/Bz;//pxy -> cpa
2309 mS[3][3]=1.;
2310 mS[4][4]=1.;
2311 HepSymMatrix mVy = helix.covariance().similarity(mS);
2312 double errorMat[15];
2313 int k = 0;
2314 for (int ie = 0 ; ie < 5 ; ie ++){
2315 for (int je = ie ; je < 5 ; je ++) {
2316 errorMat[k] = mVy[ie][je];
2317 k++;
2318 }
2319 }
2320 double p,px,py,pz;
2321 px = pxy * (-sin(helixPar[1]));
2322 py = pxy * cos(helixPar[1]);
2323 pz = pxy * helixPar[4];
2324 p = sqrt(pxy*pxy + pz*pz);
2325 //theta, phi
2326 double theta = acos(pz/p);
2327 double phi = atan2(py,px);
2328 recMdcTrack->setTrackId(trackId);
2329 recMdcTrack->setHelix(helixPar);
2330 recMdcTrack->setCharge(q);
2331 recMdcTrack->setPxy(pxy);
2332 recMdcTrack->setPx(px);
2333 recMdcTrack->setPy(py);
2334 recMdcTrack->setPz(pz);
2335 recMdcTrack->setP(p);
2336 recMdcTrack->setTheta(theta);
2337 recMdcTrack->setPhi(phi);
2338 recMdcTrack->setPoca(poca);
2339 recMdcTrack->setX(poca.x());//poca
2340 recMdcTrack->setY(poca.y());
2341 recMdcTrack->setZ(poca.z());
2342 recMdcTrack->setR(sqrt(poca.x()*poca.x() + poca.y()*poca.y()));
2343 HepPoint3D pivot(0.,0.,0.);
2344 recMdcTrack->setPivot(pivot);
2345 recMdcTrack->setVX0(0.);//pivot
2346 recMdcTrack->setVY0(0.);
2347 recMdcTrack->setVZ0(0.);
2348 recMdcTrack->setError(errorMat);
2349 recMdcTrack->setError(mVy);
2350 recMdcTrack->setChi2(chisq);
2351 recMdcTrack->setStat(tkStat);
2352 //recMdcTrack->setNhits(nHits);
2353 //-----------hit list-------------
2354 HitRefVec hitRefVec;
2355 ClusterRefVec clusterRefVec;
2356 vector<int> vecHits;
2357 map<int,int> clusterFitStat;
2358 //for fiterm
2359 int maxLayer = 0;
2360 //cout<<__FILE__ <<" "<<__LINE__ <<endl;
2361 for(TrkHitList::hot_iterator hot = aList->begin();hot!=aList->end();hot++){
2362 if(typeid(*hot)==typeid(MdcRecoHitOnTrack) || typeid(*hot)==typeid(MdcHitOnTrack) /*|| typeid(*hot)==typeid(TrkHitOnTrk)*/ ){
2363 const MdcRecoHitOnTrack* recoHot;
2364 recoHot = dynamic_cast<const MdcRecoHitOnTrack*> (&(*hot));
2365 int layerId = recoHot->mdcHit()->layernumber();
2366 int wireId = recoHot->mdcHit()->wirenumber();
2367 if(maxLayer < layerId)maxLayer = layerId;
2368 }
2369 }
2370 //cout<<"maxLayer:"<<maxLayer<<endl;
2371 int maxLayerId = -1;
2372 int minLayerId = 43;
2373 double fiTerm = 999.;
2374 const MdcRecoHitOnTrack* fiTermHot = NULL;
2375 TrkHitList::hot_iterator hot = aList->begin();
2376 for (;hot!=aList->end();hot++){
2377 //cout<<__FILE__ <<" "<<__LINE__ <<" "<< typeid(*hot).name()<<endl;
2378 if(typeid(*hot)==typeid(MdcRecoHitOnTrack) || typeid(*hot)==typeid(MdcHitOnTrack) /*|| typeid(*hot)==typeid(TrkHitOnTrk)*/ ){
2379 const MdcRecoHitOnTrack* recoHot;
2380 recoHot = dynamic_cast<const MdcRecoHitOnTrack*> (&(*hot));
2381 if(!(recoHot->isActive())) continue;// added 2020-05-26 wangll
2382 int layerId = recoHot->mdcHit()->layernumber();
2383 if(layerId>(maxLayer - m_removeNOuterHits))continue;
2384 //if (!recoHot->mdcHit()) return;
2385 RecMdcHit* recMdcHit = new RecMdcHit;
2386 //id
2387 recMdcHit->setId(hitId);
2388 //---------BESIII----------
2389 //phiWire - phiHit <0 flagLR=0 left driftleft<0 ;
2390 //phiWire - phiHit >0 flagLR=1 right driftright>0;
2391 //flag = 2 ambig;
2392 //-----Babar wireAmbig----
2393 //-1 -> right, 0 -> don't know, +1 -> left
2394 //+1 phiWire-phiHit<0 Left,
2395 //-1 phiWire-phiHit>0 Right,
2396 //0 don't know
2397 //ambig() w.r.t track direction
2398 //wireAmbig() w.r.t. wire location
2399 double hotWireAmbig = recoHot->wireAmbig();
2400 double driftDist = fabs(recoHot->drift());
2401 double sigma = recoHot->hitRms();
2402 double doca = fabs(recoHot->dcaToWire());
2403 int flagLR=2;
2404 if ( hotWireAmbig == 1){
2405 flagLR = 0; //left driftDist <0
2406 doca *= -1.;//2012-07-19
2407 }else if( hotWireAmbig == -1){
2408 flagLR = 1; //right driftDist >0
2409 }else if( hotWireAmbig == 0){
2410 flagLR = 2; //don't know
2411 }
2412 recMdcHit->setFlagLR(flagLR);
2413 recMdcHit->setDriftDistLeft((-1)*driftDist);
2414 recMdcHit->setErrDriftDistLeft(sigma);
2415 recMdcHit->setDriftDistRight(driftDist);
2416 recMdcHit->setErrDriftDistRight(sigma);
2417 //Mdc Id
2418 Identifier mdcId = recoHot->mdcHit()->digi()->identify();
2419 recMdcHit->setMdcId(mdcId);
2420 //corrected ADC
2421
2422 //contribution to chisquare
2423 //fill chisq
2424 double res=999.,rese=999.;
2425 if (recoHot->resid(res,rese,false)){
2426 }else{}
2427 double deltaChi=0;
2428 recoHot->getFitStuff(deltaChi);//yzhang open 2010-09-20
2429 recMdcHit->setChisqAdd( deltaChi * deltaChi );
2430 //set tracks containing this hit
2431 recMdcHit->setTrkId(trackId);
2432 //doca
2433 recMdcHit->setDoca(doca);//doca sign left<0
2434 //entrance angle
2435
2436 recMdcHit->setEntra(recoHot->entranceAngle());
2437 //z of hit
2438 HepPoint3D pos; Hep3Vector dir;
2439 double fltLen = recoHot->fltLen();
2440 recMdcHit->setFltLen(fltLen);
2441 recoHot->getParentRep()->traj().getInfo(fltLen,pos,dir);
2442 recMdcHit->setZhit(pos.z());
2443 double tof = recoHot->getParentRep()->arrivalTime(fltLen);
2444 recMdcHit->setTdc(recoHot->mdcHit()->tdcIndex());
2445 recMdcHit->setAdc(recoHot->mdcHit()->adcIndex());
2446 //drift time
2447 recMdcHit->setDriftT(recoHot->mdcHit()->driftTime(tof,pos.z()));
2448 //for fiterm
2449 int wireId = recoHot->mdcHit()->wirenumber();
2450 //std::cout<<" MdcTrack::store() ("<<layerId<<","<<wireId<<") fltLen "<<fltLen<<" wireAmbig "<<hotWireAmbig<<" y "<<pos.y()<<std::endl;
2451 // <<recoHot->entranceAngle()<<std::endl;
2452 if (layerId >= maxLayerId){
2453 maxLayerId = layerId;
2454 fiTermHot = recoHot;
2455 }
2456 if (layerId < minLayerId){
2457 minLayerId = layerId;
2458 }
2459 // status flag
2460 if (recoHot->isActive()) {
2461 recMdcHit->setStat(1);
2462 }else{
2463 recMdcHit->setStat(0);
2464 }
2465 // for 5.1.0 use all hits
2466 if (recoHot->layer()->view()) {
2467 ++nSt;
2468 }
2469 hitList->push_back(recMdcHit);
2470 SmartRef<RecMdcHit> refHit(recMdcHit);
2471 hitRefVec.push_back(refHit);
2472 vecHits.push_back(mdcId.get_value());
2473 ++hitId;
2474 }else if(typeid(*hot)==typeid(CgemHitOnTrack)){
2475 const CgemHitOnTrack* recoHot = dynamic_cast<const CgemHitOnTrack*> (&(*hot));
2476 const RecCgemCluster* recCgemCluster = recoHot->baseHit();
2477 int clusterid = recCgemCluster->getclusterid();
2478 int stat = recoHot->isActive();
2479 if(stat==0) continue;// added 2020-05-26 wangll
2480 //cout<<"stat:"<<stat<<endl;
2481 clusterFitStat[clusterid] = stat;
2482 //cout<<clusterid<<" "<<stat<<endl;
2483 //cout<<"clusterid:"<< recCgemCluster->getclusterid()<<" layer:"<<recCgemCluster->getlayerid()<<endl;
2484 clusterRefVec.push_back(recCgemCluster);
2485 }
2486 }
2487 std::sort(clusterRefVec.begin(),clusterRefVec.end(),sortCluster);
2488 //fi terminal angle
2489 if (fiTermHot!=NULL){
2490 fiTerm=(1./sqrt(1.+tanDip*tanDip))*fiTermHot->fltLen()*helix.omega();
2491 }
2492 recMdcTrack->setFiTerm(fiTerm);
2493 // number of stereo hits contained
2494 //recMdcTrack->setNhits(hitId);
2495 //recMdcTrack->setNster(nSt);
2496 //recMdcTrack->setNdof(nDof);
2497 //recMdcTrack->setFirstLayer(maxLayerId);
2498 //recMdcTrack->setLastLayer(minLayerId);
2499 //recMdcTrack->setFirstLayer(minLayerId);
2500 //recMdcTrack->setLastLayer(maxLayerId);
2501 //recMdcTrack->setClusterFitStat(clusterFitStat);
2502 //recMdcTrack->setVecClusters(clusterRefVec);
2503 //recMdcTrack->setNcluster(clusterRefVec.size());
2504
2505 // --- setN* functions called in setVec* functions
2506 recMdcTrack->setVecHits(hitRefVec);
2507 recMdcTrack->setVecClusters(clusterRefVec,clusterFitStat);
2508 trackList->push_back(recMdcTrack);
2509 trackId++;
2510 }
2511 //cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
2512 /*
2513 int trackId(0);
2514 for(vector<HoughTrack>::iterator trkIT = trackVector.begin();trkIT!=trackVector.end();trkIT++){
2515//TrkErrCode trkErrCode = trkIT->fitCircle(m_mdcDetector,m_trkContextEv,m_bunchT0);
2516HoughTrack* houghTrack = &(*trkIT);
2517if(houghTrack->getFlag() == 1)continue;
2518if(houghTrack->getFlag() < 0)continue;
2519//houghTrack->print();
2520//houghTrack->printHot();
2521trackId=trackList->size();
2522//cout<<"start store trk "<<trackId;
2523RecMdcTrack* recMdcTrack = new RecMdcTrack();
2524//vector<HoughHit>* hotList = houghTrack->getHot();
2525//vector<HoughHit*> hotList = houghTrack->getVecHitPnt();
2526vector<HoughHit*> hotList = houghTrack->getHotList();
2527//cout<<" with "<<hotList.size()<<" hits";//<<endl;
2528double helixPar[5];
2529helixPar[0] = houghTrack->dr();
2530helixPar[1] = houghTrack->phi0();
2531helixPar[2] = houghTrack->kappa();
2532helixPar[3] = houghTrack->dz();
2533helixPar[4] = houghTrack->tanl();
2534int q = houghTrack->getCharge();
2535double pxy = houghTrack->pt();
2536double px = houghTrack->momentum(0).x();
2537double py = houghTrack->momentum(0).y();
2538double pz = houghTrack->momentum(0).z();
2539double p = houghTrack->momentum(0).mag();
2540double theta = houghTrack->direction(0).theta();
2541double phi = houghTrack->direction(0).phi();
2542HepPoint3D poca = houghTrack->x(0);
2543HepPoint3D pivot = houghTrack->pivot();
2544double r = poca.perp();
2545HepSymMatrix Ea = houghTrack->Ea();
2546//cout<<" phi, pxy, pz = "<<phi<<", "<<pxy<<", "<<pz<<endl;
2547double errorMat[15];
2548int k = 0;
2549for (int ie = 0 ; ie < 5 ; ie ++){
2550for (int je = ie ; je < 5 ; je ++){
2551errorMat[k] = Ea[ie][je];
2552k++;
2553}
2554}
2555double chisq = houghTrack->getChi2();
2556int tkStat = 4+houghTrack->getCircleFitStat();
2557//if(tkStat==4) cout<<" track "<<trackId<<" has no good circle fit"<<endl;
2558int nHits = hotList.size();
2559
2560recMdcTrack->setTrackId(trackId);
2561recMdcTrack->setHelix(helixPar);
2562recMdcTrack->setCharge(q);
2563recMdcTrack->setPxy(pxy);
2564recMdcTrack->setPx(px);
2565recMdcTrack->setPy(py);
2566recMdcTrack->setPz(pz);
2567recMdcTrack->setP(p);
2568recMdcTrack->setTheta(theta);
2569recMdcTrack->setPhi(phi);
2570recMdcTrack->setPoca(poca);
2571recMdcTrack->setX(poca.x());//poca
2572recMdcTrack->setY(poca.y());
2573recMdcTrack->setZ(poca.z());
2574recMdcTrack->setR(r);
2575recMdcTrack->setPivot(pivot);
2576recMdcTrack->setVX0(0.);//pivot
2577recMdcTrack->setVY0(0.);
2578recMdcTrack->setVZ0(0.);
2579recMdcTrack->setError(errorMat);
2580recMdcTrack->setError(Ea);
2581recMdcTrack->setChi2(chisq);
2582recMdcTrack->setStat(tkStat);
2583recMdcTrack->setNhits(nHits);
2584//-----------hit list-------------
2585int hitId = 0;
2586int nSt(0);
2587int maxLayerId = -1;
2588int minLayerId = 43;
2589double fiTerm = 999.;
2590HoughHit fiTermHot;
2591
2592HitRefVec hitRefVec;
2593ClusterRefVec clusterRefVec;
2594map<int,int> clusterFitStat;
2595for(vector<HoughHit*>::iterator hotIt = hotList.begin(); hotIt != hotList.end();hotIt++)
2596{
2597 //cout<<"handle hit "<<hitId<<endl;
2598 HoughHit* hot(*hotIt);
2599 //int layer = (**hotIt).getLayer();
2600 //int wire = (**hotIt).getWire();
2601 //cout<<"("<<setw(2)<<layer<<","<<setw(3)<<wire<<") ";
2602 if(hot->getHitType()==HoughHit::MDCHIT){
2603 //cout<<"create a new RecMdcHit"<<endl;
2604 RecMdcHit* recMdcHit = new RecMdcHit;
2605
2606 recMdcHit->setId(hitId);
2607 recMdcHit->setTrkId(trackId);
2608 HepPoint3D hitPoint = hot->getHitPosition();
2609 double dPhi = houghTrack->dPhi(hitPoint);
2610 HepPoint3D position = houghTrack->x(dPhi);
2611 Hep3Vector direction = houghTrack->direction(dPhi);
2612 //cout<<"get 1"<<endl;
2613
2614 double ddl = -1*hot->getDriftDist();
2615 double ddr = hot->getDriftDist();
2616 //double erddl = hot->hitSigma();
2617 //double erddr = hot->hitSigma();
2618 double pChisq = hot->getResidual()*hot->getResidual();//FIXME
2619 int lr = 0;
2620 int stat = hot->getUse();
2621 stat = 1; // llwang
2622 //cout<<"hit stat = "<<stat<<endl;
2623 //cout<<"get 2"<<endl;
2624 Identifier mdcId = hot->getDigi()->identify();
2625 //cout<<"get 2.1"<<endl;
2626 double tdc = hot->getDigi()->getTimeChannel();
2627 //cout<<"get 2.2"<<endl;
2628 double adc = hot->getDigi()->getChargeChannel();
2629 //cout<<"get 2.3"<<endl;
2630 double driftT = hot->driftTime();
2631 //cout<<"get 2.4"<<endl;
2632 double doca = hot->getDriftDist() +hot->getResidual();
2633 //cout<<"get 2.5"<<endl;
2634 double entra = direction.phi()-position.phi();//FIXME
2635 //cout<<"get 2.6"<<endl;
2636 while(entra<-0.5*M_PI)entra+= M_PI;
2637 while(entra> 0.5*M_PI)entra -= M_PI;
2638 //cout<<"get 3"<<endl;
2639 double zhit = hitPoint.z();
2640 double fltLen = houghTrack->flightLength(hitPoint);
2641 //cout<<"after get "<<hitId<<endl;
2642
2643 recMdcHit->setDriftDistLeft(ddl);
2644 recMdcHit->setDriftDistRight(ddr);
2645 //recMdcHit->setErrDriftDistLeft(erddl);
2646 //recMdcHit->setErrDriftDistRight(erddr);
2647 recMdcHit->setChisqAdd(pChisq);
2648 recMdcHit->setFlagLR(lr);
2649 recMdcHit->setStat(stat);
2650 recMdcHit->setMdcId(mdcId);
2651 recMdcHit->setTdc(tdc);
2652 recMdcHit->setAdc(adc);
2653 recMdcHit->setDriftT(driftT);
2654 recMdcHit->setDoca(doca);
2655 recMdcHit->setEntra(entra);
2656 recMdcHit->setZhit(zhit);
2657 recMdcHit->setFltLen(fltLen);
2658 //cout<<"after set "<<hitId<<endl;
2659
2660 hitList->push_back(recMdcHit);
2661 SmartRef<RecMdcHit> refHit(recMdcHit);
2662 hitRefVec.push_back(refHit);
2663
2664 if(hot->getLayer()>maxLayerId){
2665 maxLayerId = hot->getLayer();
2666 fiTermHot = *hot;
2667 }
2668 if(hot->getLayer()<minLayerId){
2669 minLayerId = hot->getLayer();
2670 }
2671 if(hot->getUse()==1){
2672 recMdcHit->setStat(1);
2673 }else{
2674 recMdcHit->setStat(0);
2675 }
2676 if(hot->getFlag()!=0)++nSt;
2677 //cout<<"finish a DC hit "<<hitId<<endl;
2678 }else if(hot->getHitType()==HoughHit::CGEMHIT){
2679 //hot->print();
2680 //cout<<endl;
2681 const RecCgemCluster* recCgemCluster = hot->getCgemCluster();
2682 int clusterid = hot->getCgemCluster()->getclusterid();
2683 //int stat = hot->getUse();
2684 int stat = 1;
2685 clusterFitStat[clusterid] = stat;
2686 clusterRefVec.push_back(recCgemCluster);
2687 }
2688 hitId++;
2689}
2690
2691//HepPoint3D point = fiTermHot.getHitPosition();
2692//fiTerm = houghTrack->flightArc(point)/houghTrack->radius();
2693//recMdcTrack->setFiTerm(fiTerm);
2694recMdcTrack->setNdof(nHits-5);
2695recMdcTrack->setNster(nSt);
2696recMdcTrack->setFirstLayer(minLayerId);
2697recMdcTrack->setLastLayer(maxLayerId);
2698//cout<<"push back a RecMdcTrack with "<<recMdcTrack->getNhits()<<" hits, "<<recMdcTrack->getNcluster()<<" clusters"<<endl;
2699recMdcTrack->setVecHits(hitRefVec);
2700//cout<<"before setVecClusters"<<endl;
2701//recMdcTrack->setVecClusters(clusterRefVec,clusterFitStat);
2702//recMdcTrack->setVecClusters(clusterRefVec);
2703recMdcTrack->setVecClusters(clusterRefVec,clusterFitStat);
2704//cout<<"clusterRefVec.size = "<<clusterRefVec.size()<<endl;
2705//cout<<"end setVecClusters"<<endl;
2706recMdcTrack->setNcluster(clusterRefVec.size());
2707//cout<<"push back a RecMdcTrack with "<<recMdcTrack->getNhits()<<" hits, "<<recMdcTrack->getNcluster()<<" clusters"<<endl;
2708trackList->push_back(recMdcTrack);
2709//trackId++;
2710//cout<<helixPar[2]<<endl;
2711}
2712return trackList->size();
2713// */
2714return trackList->size();
2715}
2716
2718{
2719 //cout<<"nHit ==========> "<<m_houghHitList.size()<<endl;
2720 cout<<"========== truth =========="<<endl;
2721 for(HitVector_Iterator hitIt=m_mcHitCol.begin();hitIt!=m_mcHitCol.end();hitIt++){
2722 hitIt->print();
2723 }
2724 cout<<endl;
2725 cout<<"========== Digi =========="<<endl;
2726 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end();hitIt++)
2727 {
2728 hitIt->print();
2729 }
2730 cout<<endl;
2731 /*
2732 {
2733 vector<HoughHit>& hitList = m_mcHitCol;
2734 for(HitVector_Iterator hitIt = hitList.begin(); hitIt != hitList.end();hitIt++){
2735 cout<<setw(4)<<hitIt->getHitID();
2736 cout<<"("<<setw(2)<<hitIt->getLayer()<<", "<<setw(3)<<hitIt->getWire()<<") ";
2737 cout<<"("<<setw(10)<<hitIt->getHitPosition().x()<<", "<<setw(10)<<hitIt->getHitPosition().y()<<", "<<setw(10)<<hitIt->getHitPosition().z()<<") ";
2738 vector<int> trkID = hitIt->getTrkID();
2739 cout<<"trkID:"<<setw(4)<<trkID[0];
2740 cout<<"half:"<<setw(4)<<hitIt->getHalfCircle();
2741 if(hitIt->getHitType()==HoughHit::CGEMMCHIT){
2742 if(hitIt->getCgemCluster()!=NULL){
2743 //cout<<hitIt->getFlag()<<" ";
2744 //if(hitIt->getFlag()==2)
2745 cout<<setw(5)<<hitIt->getCgemCluster()->getclusterid();
2746 cout<<"["<<setw(3)<<hitIt->getCgemCluster()->getclusterflagb()<<", "<<setw(3)<<hitIt->getCgemCluster()->getclusterflage()<<"] ";
2747 }
2748 //else cout<<"NULL ";
2749 }
2750 else{
2751 if(hitIt->getDigi()!=NULL){
2752 cout<<setw(5)<<hitIt->getDigi()->getTrackIndex();
2753 cout<<hitIt->getDigi()->identify();
2754 }
2755 //else cout<<"NULL ";
2756
2757 }
2758 cout<<endl;
2759 }
2760 }
2761 cout<<endl;
2762 //*/
2763 /*
2764 {
2765 vector<HoughHit>& hitList = m_houghHitList;
2766 cout<<hitList.size()<<endl;
2767 for(HitVector_Iterator hitIt = hitList.begin(); hitIt != hitList.end();hitIt++){
2768 cout<<setw(4)<<hitIt->getHitID();
2769 cout<<"("<<setw(2)<<hitIt->getLayer()<<", "<<setw(3)<<hitIt->getWire()<<") ";
2770 cout<<"("<<setw(10)<<hitIt->getHitPosition().x()<<", "<<setw(10)<<hitIt->getHitPosition().y()<<", "<<setw(10)<<hitIt->getHitPosition().z()<<") ";
2771 cout<<setw(4)<<hitIt->getFlag();
2772 if(hitIt->getHitType()==HoughHit::CGEMHIT){
2773 cout<<setw(4)<<hitIt->getCgemCluster()->getclusterid();
2774 cout<<"["<<setw(4)<<hitIt->getCgemCluster()->getclusterflagb()<<", "<<setw(4)<<hitIt->getCgemCluster()->getclusterflage()<<"] ";
2775 }
2776 else{
2777 cout<<setw(5)<<hitIt->getDigi()->getTrackIndex();
2778 cout<<hitIt->getDigi()->identify()<<" ";
2779 //cout<<"("<<hitIt->getPairHit()->getLayer()<<", "<<hitIt->getPairHit()->getWire()<<") ";
2780 //if(hitIt->getPairHit()!=NULL)cout<<hitIt->getDriftDist()<<" "<<hitIt->getPairHit()->getDriftDist()<<" "<<hitIt->getDriftDist()-hitIt->getPairHit()->getDriftDist()<<endl;
2781 }
2782 if(hitIt->getPairHit()!=NULL)cout<<hitIt->getPairHit()->getHitID();
2783 //else cout<<"NULL";
2784 cout<<endl;
2785 }
2786 }
2787 cout<<endl;
2788 // */
2789}
2790
2791
2792int HoughFinder::searchCircle()
2793{
2794 //m_debug=false;
2795 //m_debug=true;
2796 if(m_debug==5) {
2797 cout<<"***************************************"<<endl;
2798 cout<<"start circle search : "<<endl;
2799 }
2800 m_triedCellInRoughMap.clear();
2801 bool tryCgemLeftOnly=false;
2802 while(true)
2803 {
2804 int charge=0;
2805 // --- fill rough map
2806 int nXhitsLeft=0;
2807 m_roughRhoThetaMap.Reset();
2808 //int charge=0;
2809 int vote=1;
2810
2811 //cout<<"searchCircle "<<__LINE__<<endl;
2812 nXhitsLeft = fillHistogram(m_XHoughHitList,&m_roughRhoThetaMap,charge,vote);
2813 //cout<<"searchCircle "<<__LINE__<<endl;
2814 if(m_debug==5) {
2815 cout<<"------------------------------------------------------------------------------------ "<<endl;
2816 cout<<"nXhitsLeft = "<<nXhitsLeft<<endl;
2817 }
2818
2819 if(nXhitsLeft<3) {
2820 if(!tryCgemLeftOnly) {
2821 int nCgemHitsLeft = activeUnusedCgemHitsOnly(m_XHoughHitList);
2822 tryCgemLeftOnly=true;
2823 if(nCgemHitsLeft>=3) {
2824 if(m_debug==5) cout<<"Now try CGEM left only"<<endl;
2825 continue;
2826 }
2827 }
2828 break;
2829 }
2830
2831 // --- find the peak position on rough Hough map
2832 double x_peak(0.), y_peak(0.);
2833 double x_weight(0.), y_weight(0.);
2834 getWeightedPeak(m_roughRhoThetaMap, x_peak, y_peak, x_weight, y_weight);
2835 if(m_debug==5) cout<<"rough x_weight, y_weight = "<<x_weight<<", "<<y_weight<<endl;
2836 //cout<<endl;
2837
2838 // --- range for fine map
2839 x_peak = x_weight;
2840 y_peak = y_weight;
2841 double x_min=x_peak-0.5*m_ExtPeak_theta*M_PI/m_nBinTheta;
2842 double x_max=x_peak+0.5*m_ExtPeak_theta*M_PI/m_nBinTheta;
2843 double y_min=y_peak-0.5*m_ExtPeak_rho*0.2/m_nBinRho;
2844 double y_max=y_peak+0.5*m_ExtPeak_rho*0.2/m_nBinRho;
2845
2846 // --- binning for fine map
2847 int nFineBin_Theta = nFineBinTheta(y_peak);
2848 int nFineBin_Rho = nFineBinRho(y_peak);
2849 if(m_debug==5) cout<<"nThetaFine, nRhoFine = "<<nFineBin_Theta<<", "<<nFineBin_Rho<<endl;
2850
2851 int trkFoundThisTry = 0;
2852 int NHitTried = 0;
2853 // --- loop -/+ hypotheses
2854 for(charge=-1; charge<2; charge+=2)
2855 {
2856
2857 if(m_debug==5) cout<<"/******** Try iCharge = "<<charge<<" **********/"<<endl;
2858
2859 // create a rough track candidate
2860 int trkID = m_houghTrackList.size();
2861 double binTheta(0.), binRho(0.);
2862 HoughTrack track(charge, x_peak, y_peak, binTheta, binRho, trkID);
2863 if(m_debug==5) cout<<"circle center = "<<track.center()<<endl;
2864 // --- fill the fine map
2865 m_fineRhoThetaMap.Reset();
2866 m_fineRhoThetaMap.SetBins(nFineBin_Theta,x_min,x_max,nFineBin_Rho,y_min,y_max);
2867 vote=1;
2868 int nHitFilled(0);
2869 //track.print();
2870 if(fabs(y_weight)<0.02) // > 300 MeV
2871 {
2872 //cout<<"fill high pt histogram"<<endl;
2873 nHitFilled = fillHistogram(m_XHoughHitList,&m_fineRhoThetaMap,0,vote);
2874 }
2875 else
2876 {
2877 //cout<<"fill low pt histogram"<<endl;
2878 nHitFilled = fillHistogram(m_XHoughHitList,&m_fineRhoThetaMap,charge,vote);
2879 }
2880 if(nHitFilled<3) {
2881 if(m_debug==5) cout<<"nHitFilled<3 -> continue"<<endl;
2882 //delete track;
2883 continue;
2884 }
2885 double theta_peak, rho_peak, theta_weight, rho_weight;
2886 getWeightedPeak(m_fineRhoThetaMap, theta_peak, rho_peak, theta_weight, rho_weight);
2887
2888 // update the track candidate
2889 track.update(theta_weight,rho_weight);
2890 //cout<<" ============== before fitting ================="<<endl;
2891 //cout<<"fine x_weight, y_weight = "<<theta_weight<<", "<<rho_weight<<endl;
2892 //track.print();
2893
2894 // --- select X-view hits
2895 //vector<HoughHit*> XHitList_sel;
2896 int flag=0;// only X-view hits
2897 track.resetNhitHalf();
2898 int nXsel(0);
2899 if(fabs(y_weight)<0.02) // > 300 MeV
2900 {
2901 track.findXHot(m_XHoughHitList,0);
2902 //if(track->getNhitFirstHalf()<track->getNhitSecondHalf())
2903 if(charge==-1&&track.getNhitUnusedFirstHalf()<track.getNhitUnusedSecondHalf())
2904 {
2905 if(m_debug==5) cout<<"--- the second half has more hits, try next charge: "<<endl;
2906 //delete track;
2907 continue;
2908 }
2909 else
2910 {
2911 track.clearHits();
2912 //XHitList_sel.clear();
2913 if(m_debug==5) cout<<" --- the first half has more hits, go ahead: "<<endl;
2914 }
2915 }
2916 nXsel = track.findXHot(m_XHoughHitList, charge);
2917 //track.printHot();
2918 NHitTried = track.getNTried();
2919 if(m_debug==5) {
2920 cout<<"sel "<<nXsel<<" hits, "<<NHitTried<<" new hits tried"<<endl;
2921 track.printHot(0);
2922 }
2923
2924 //if(track.isAGoodCircle())
2925 if(nXsel>=3)
2926 {
2927 //track.printHot();
2928 //track.print();
2929 //TrkContextEv* trkContextEv = new TrkContextEv(m_bfield);
2930 //if(m_fitFlag>0)TrkErrCode trkErrCode = track.fitCircle(m_mdcDetector,trkContextEv,m_bunchT0);
2931 int fitFlag_circle = 0;
2932 if(m_fitFlag>0)
2933 {
2934 //TrkErrCode trkErrCode = track.fitCircle(m_mdcDetector,m_trkContextEv,m_bunchT0);
2935 //if(m_debug)
2936 //cout<<"circle helix from TrkFitter"<<track.a()<<", chi2="<<track.getChi2()<<endl;
2937 //cout<<"m_bunchT0 = "<<m_bunchT0<<endl;
2938 //track.update(theta_weight,rho_weight);
2939 //cout<<"to start circle fit"<<endl;
2940 fitFlag_circle = track.fitCircle(&myDotsHelixFitter,m_bunchT0*1e9, m_circle_chiCut, m_debug);// FIXME, try track from IP first, track with ODC hits only?
2941 //cout<<"circle fit ends"<<endl;
2942 if(fitFlag_circle==0)
2943 {
2944 HepVector a_circle_fit = myDotsHelixFitter.getHelix();
2945 track.updateCirclePar(a_circle_fit[0], a_circle_fit[1], a_circle_fit[2]);
2946 track.clearHits();
2947 int nXsel_new = track.findXHot(m_XHoughHitList, charge);// too loose? FIXME
2948 int nDrop = track.dropRedundentCgemXHits();// or tag them only? FIXME
2949 if(m_debug==5) {
2950 cout<<" sel "<<nXsel_new<<" hits after fitCircle, fitted pt = "<<track.pt();
2951 if(nDrop>0) cout<<", drop "<<nDrop<<" redundent CgemXHits";
2952 cout<<endl;
2953 track.printHot(0);
2954 }
2955 NHitTried = track.getNTried();
2956 if(nXsel_new==0||NHitTried==0) {
2957 track.update(theta_weight,rho_weight);
2958 nXsel = track.findXHot(m_XHoughHitList, charge);
2959 NHitTried = track.getNTried();
2960 }
2961 //cout<<" ============== after fitting ================="<<endl;
2962 //track.printHot();
2963 //track.print();
2964 }// good circle fit
2965 //else if(m_debug) cout<<"fitCircle failed "<<endl;
2966 }// if do circle fit
2967 //track.print();
2968
2969 //*/
2970 //track.markUsedHot(XHitList_sel);
2971 if(track.isAGoodCircle())
2972 {
2973 track.markUsedHot(1);
2974 //track.setMdcHit( &m_mdcHitCol);
2975 m_houghTrackList.push_back(track);
2976 if(m_debug==5) cout<<"save this circle trk"<<endl;
2977 //track.print();
2978 //track.printHot();
2979 trkFoundThisTry++;
2980 break;// a good circle found, search next peak
2981 }
2982 //else
2983 //{
2984 // if(m_debug) cout<<"drop this circle trk"<<endl;
2985 // track.markUsedHot(-1);
2986 //}
2987 }// >= 3 hits
2988 //else
2989 //{
2990 // --- drop the circle track
2991 if(m_debug==5) cout<<"drop this circle trk"<<endl;
2992 //track.markUsedHot(XHitList_sel, -1);
2993 track.markUsedHot(-1);// drop too many hits? FIXME
2994 //delete track;
2995 //}
2996 }// loop charge
2997 if(NHitTried==0)
2998 {
2999 if(m_debug==5) cout<<"no new hits tried in this try"<<endl;
3000 if(!tryCgemLeftOnly) {
3001 int nCgemHitsLeft = activeUnusedCgemHitsOnly(m_XHoughHitList);
3002 tryCgemLeftOnly=true;
3003 if(m_debug==5) cout<<"check nCgemHitsLeft="<<nCgemHitsLeft<<endl;
3004 if(nCgemHitsLeft>=3) {
3005 if(m_debug==5) cout<<"Now try CGEM left only"<<endl;
3006 continue;
3007 }
3008 }
3009 if(m_debug==5) cout<<"stop circle trk finding "<<endl;
3010 break;
3011 }
3012 }// while
3013
3014 //m_debug=false;
3015 return 1;
3016}
3017
3018int HoughFinder::searchCircle2()
3019{
3020 //m_debug=true;
3021 if(m_debug) {
3022 cout<<"***************************************"<<endl;
3023 cout<<"start circle search : "<<endl;
3024 }
3025 m_roughRhoThetaMap.Reset();
3026 int charge=0;
3027 int nXhitsLeft=0;
3028 int vote=1;
3029 nXhitsLeft = fillHistogram(m_XHoughHitList,&m_roughRhoThetaMap,charge,vote);
3030
3031 if(nXhitsLeft<=3) return 0;
3032
3033 // --- find local peaks
3034
3035}
3036
3037void HoughFinder::getWeightedPeak(TH2D& h, double& x_peak, double& y_peak, double& x_weight, double& y_weight, int x_ext, int y_ext)
3038{
3039 int ix_max, iy_max, iz_max;
3040 h.GetMaximumBin(ix_max, iy_max, iz_max);
3041 int nx=h.GetXaxis()->GetNbins();
3042 int ny=h.GetYaxis()->GetNbins();
3043 //cout<<"peak at "<<ix_max<<", "<<iy_max<<" in a map "<<nx<<" * "<<ny<<endl;
3044
3045 if(ix_max==0&&iy_max==0) {
3046 //cout<<"nx, ny = "<<nx<<", "<<ny<<endl;
3047 for(int i=0; i<nx; i++)
3048 {
3049 //cout<<endl;
3050 for(int j=0; j<ny; j++)
3051 {
3052 double n_tmp = h.GetBinContent(i,j);
3053 //cout<<n_tmp<<" ";
3054 }
3055 }
3056 }
3057
3058 x_peak=h.GetXaxis()->GetBinCenter(ix_max);
3059 y_peak=h.GetYaxis()->GetBinCenter(iy_max);
3060 x_weight=0.; y_weight=0.;
3061 double weight(0.);
3062 if(x_ext>=0&&y_ext>=0) {
3063 for(int i1=ix_max-x_ext; i1<=ix_max+x_ext; i1++)
3064 {
3065 double x_tmp = h.GetXaxis()->GetBinCenter(i1);
3066 int i1_tmp = i1;
3067 //if(i1<1) i1_tmp=m_nBinTheta+i1;
3068 //if(i1>1) i1_tmp=m_nBinTheta+i1;
3069 //if(i1==m_nBinTheta+1) i1_tmp=1;
3070 for(int i2=iy_max-y_ext; i2<=iy_max+y_ext; i2++)
3071 {
3072 double n_tmp = h.GetBinContent(i1_tmp,i2);
3073 if(i2<1||i2>ny) n_tmp=0.;
3074 if(i1<1||i1>nx) n_tmp=0.;
3075 weight+=n_tmp;
3076 double y_tmp = h.GetYaxis()->GetBinCenter(i2);
3077 x_weight+=x_tmp*n_tmp;
3078 y_weight+=y_tmp*n_tmp;
3079 //cout<<"i1,i2="<<i1<<","<<i2<<endl;
3080 }
3081 }
3082 x_weight=x_weight/weight;
3083 y_weight=y_weight/weight;
3084 }
3085 else {
3086 x_weight=x_peak;
3087 y_weight=y_peak;
3088 }
3089}
3090
3091void HoughFinder::getLocalPeaks(TH2D& h, int minCut)
3092{
3093 int nx=h.GetXaxis()->GetNbins();
3094 int ny=h.GetYaxis()->GetNbins();
3095 vector<int> cell_locMax(nx*ny,0);
3096 for(int i=0; i<nx; i++)
3097 {
3098 for(int j=0; j<ny; j++)
3099 {
3100 int index=i+j*nx;
3101 if(h.GetBinContent(i+1,j+1)<minCut) continue;
3102 if(cell_locMax[index]<0) continue;
3103 for(int i1=max(i-1,0); i1<min(i+2,nx); i1++)
3104 {
3105 for(int j1=max(j-1,0); j1<min(j+2,ny); j1++)
3106 {
3107 if(i==i1&&j==j1) continue;
3108 if(h.GetBinContent(i+1,j+1)<=h.GetBinContent(i1+1,j1+1)) {
3109 cell_locMax[index]=-1;
3110 break;
3111 }
3112 else //if(h.GetBinContent(i+1,j+1)>h.GetBinContent(i1+1,j1+1))
3113 {
3114 cell_locMax[i1+j1*nx]=-1;
3115 //cell_locMax[index]++;
3116 }
3117 }
3118 if(cell_locMax[index]<0) break;
3119 }
3120 if(cell_locMax[index]==0) {
3121 cout<<"a local maximum found ("<<i<<", "<<j<<")"<<endl;
3122 }
3123 }
3124 }
3125}
3126
3127int HoughFinder::nFineBinTheta(double rho)
3128{
3129 double rho_rough = fabs(rho);
3130 double k_theta = (600.-1200.)/0.0335;
3131 int nThetaFine = int(k_theta*rho_rough+1200);
3132 if(nThetaFine<500) nThetaFine=500;
3133 //cout<<"rho_rough, nThetaFine = "<<rho_rough<<", "<<nThetaFine<<endl;
3134 //cout<<"nThetaFine = "<<nThetaFine<<endl;
3135 nThetaFine=ceil(1.0*nThetaFine/m_nBinTheta*m_ExtPeak_theta);
3136 return nThetaFine;
3137}
3138
3139int HoughFinder::nFineBinRho(double rho)
3140{
3141 double rho_rough = fabs(rho);
3142 int nRhoFine = 50;
3143 if(rho_rough<0.0198)
3144 {
3145 double k1_rho = (850.-1200.)/0.0198;
3146 nRhoFine=int(k1_rho*rho_rough+1200);
3147 }
3148 else if(rho_rough<0.03)
3149 {
3150 double k2_rho = (300.-850.)/(0.03-0.0198);
3151 nRhoFine=int(k2_rho*(rho_rough-0.0198)+850.);
3152 }
3153 else
3154 {
3155 double k3_rho = (100.-300.)/(0.056-0.03);
3156 nRhoFine=int(k3_rho*(rho_rough-0.03)+300.);
3157 if(nRhoFine<50) nRhoFine=50;
3158 }
3159 //cout<<"nRhoFine = "<<nRhoFine<<endl;
3160 nRhoFine=ceil(1.0*nRhoFine/m_nBinRho*m_ExtPeak_rho);
3161
3162 return nRhoFine;
3163}
3164
3165void HoughFinder::XhitCutWindow(double rho, int ilayer, double charge, double& cut1, double &cut2)
3166{
3167 rho=fabs(rho);
3168 if(rho>0.07) rho=0.07;
3169 TGraph* g_cut1, *g_cut2;
3170 if(ilayer<=3) {
3171 g_cut1=m_cut1_cgem;
3172 g_cut2=m_cut2_cgem;
3173 }
3174 else if(ilayer<=19) {
3175 g_cut1=m_cut1_ODC1;
3176 g_cut2=m_cut2_ODC1;
3177 }
3178 else if(ilayer<=42) {
3179 g_cut1=m_cut1_ODC2;
3180 g_cut2=m_cut2_ODC2;
3181 }
3182 // charge < 0
3183 cut1=g_cut1->Eval(rho);
3184 cut2=g_cut2->Eval(rho);
3185 if(charge>0) {// charge > 0
3186 double cut=cut1;
3187 cut1=-1*cut2;
3188 cut2=-1*cut;
3189 }
3190 else {// charge = 0
3191 double cut=max(fabs(cut1),fabs(cut2));
3192 cut1=-1*cut;
3193 cut2=cut;
3194 }
3195 cut1=1.1*cut1;
3196 cut2=1.1*cut2;
3197}
3198
3199void HoughFinder::clearTrack(vector<HoughTrack>& trackVector)
3200{
3201 /*
3202 vector<HoughTrack*>::iterator it = trackVector.begin();
3203 for(; it!=trackVector.end(); it++)
3204 {
3205 HoughTrack* trk = (*it);
3206 delete trk;
3207 }
3208 */
3209 trackVector.clear();
3210}
3211
3213{
3214 //cout<<"m_mdcHitCol.size()"<<m_mdcHitCol.size()<<endl;
3215 vector<MdcHit*>::iterator imdcHit = m_mdcHitCol.begin();
3216 for(;imdcHit != m_mdcHitCol.end();imdcHit++){
3217 delete (*imdcHit);
3218 }
3219
3220 for(vector<HoughTrack>::iterator trkIT = m_houghTrackList.begin();trkIT!=m_houghTrackList.end();trkIT++){
3221 trkIT->clearMemory();
3222 //TrkRecoTrk* trkRecoTrk = trkIT->getTrkRecoTrk();
3223 //delete trkRecoTrk;
3224 }
3225}
3226
3227
3228int HoughFinder::activeUnusedCgemHitsOnly(vector<HoughHit*>& hitPntList)
3229{
3230 int nCgemLeft(0);
3231 vector<HoughHit*>::iterator iter = hitPntList.begin();
3232 for(; iter!=hitPntList.end(); iter++)
3233 {
3234 //if((*iter)->getPairHit()==NULL) continue;// FIXME
3235 //if((*iter)->getPairHit()->getHalfCircle()!=1)continue;// FIXME
3236 int useOld = (*iter)->getUse();
3237 int iLayer = (*iter)->getLayer();
3238 if(iLayer<3) {
3239 if(useOld==-1||useOld==0) {
3240 (*iter)->setUse(0);
3241 nCgemLeft++;
3242 }
3243 }
3244 else
3245 if(useOld==0) (*iter)->setUse(-1);
3246 }
3247
3248 return nCgemLeft;
3249}
3250
3251// re-associate shard hits, llwang 2018-12-26
3252void HoughFinder::solveSharedHits(vector<HoughHit*>& hitList)
3253{
3254 vector<HoughHit*>::iterator itHit = hitList.begin();
3255 for(; itHit!=hitList.end(); itHit++)
3256 {
3257 //vector<HoughTrack*> trkPntList = it->getTrkPntVec();
3258 //int nTrkSharing = trkPntList.size();
3259 vector<int> trkIdList = (*itHit)->getTrkID();
3260 int nTrkSharing = trkIdList.size();
3261 //cout<<"nTrkSharing = "<<nTrkSharing<<endl;
3262 if(nTrkSharing>1) {
3263 //cout<<"found one hit shared by "<<nTrkSharing<<" trks: layer "<<(*itHit)->getLayer()
3264 //<<", pos("<<(*itHit)->getHitPosition().x()<<","<<(*itHit)->getHitPosition().y()<<") with ";
3265 int trkId_minDelD=-1;
3266 double minResid = 99.0;
3267 //vector<int> trkIdList_toDel;
3268 vector<double> vecRes = (*itHit)->getVecResid();
3269 int nTrk = vecRes.size();
3270 //cout<<nTrk<<" residuals: ";
3271 for(int i=0; i<nTrk; i++)// find out the minimum residual
3272 {
3273 //cout<<" trk "<<trkIdList[i]<<":"<<vecRes[i];
3274 if(minResid>fabs(vecRes[i])) {
3275 minResid=fabs(vecRes[i]);
3276 trkId_minDelD=trkIdList[i];
3277 }
3278 }
3279 //cout<<endl;
3280 //cout<<" trkId_minDelD, minResid = "<<trkId_minDelD<<", "<<minResid<<endl;
3281 for(int i=0; i<nTrk; i++)// remove other associations
3282 {
3283 if(trkIdList[i]!=trkId_minDelD) {
3284 (*itHit)->dropTrkID(trkIdList[i]);// remove the trk from the hit
3285 vector<HoughTrack>::iterator itTrk = getHoughTrkIt(m_houghTrackList,trkIdList[i]);
3286 if(itTrk!=m_houghTrackList.end()) itTrk->dropHitPnt(&(*(*itHit)));// remove the hit from the trk
3287 }
3288 }
3289 trkIdList = (*itHit)->getTrkID();
3290 nTrkSharing = trkIdList.size();
3291 //cout<<"new nTrkSharing = "<<nTrkSharing<<endl;
3292 }// if(nTrkSharing>1)
3293 }// loop hits
3294}
3295
3296
3297vector<HoughTrack>::iterator HoughFinder::getHoughTrkIt(vector<HoughTrack>& houghTrkList, int trkId)
3298{
3299 vector<HoughTrack>::iterator it = houghTrkList.begin();
3300 for(; it!=houghTrkList.end(); it++)
3301 {
3302 if(it->getTrkID()==trkId) break;
3303 }
3304 return it;
3305}
3306
3307//void HoughFinder::updateXHitsStatistics(vector<HoughTrack>& trackVector)
3308//{
3309//}
3310
3311int HoughFinder::associateVHits()
3312{
3313 //m_debug=true;
3314 //int trkSize = m_houghTrackList.size();
3315 //cout<<"found "<<trkSize<<" circles on x-y plane"<<endl;
3316 if(m_debug==5)
3317 {
3318 cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
3319 cout<<" start V hits association: "<<endl;
3320 }
3321 //cout<<__FILE__<<" "<<__LINE__<<endl;
3322 for(vector<HoughTrack>::iterator trkIT = m_houghTrackList.begin(); trkIT!=m_houghTrackList.end(); trkIT++)// loop circles
3323 {
3324 // --- check circle track
3325 //trkIT->print();
3326 //trkIT->printHot();
3327 //HoughTrack* trkCandi = m_houghTrackList[i];
3328 if(trkIT->getFlag()!=0) continue; // skip bad circle candidates
3329 trkIT->updateLayerStat();
3330 if(m_debug==5) {
3331 cout<<"try V-hits association for circle: "<<trkIT->getTrkID()<<endl;
3332 cout<<"if near stereo hits: "<<trkIT->nearStereoHits()<<endl;
3333 }
3334 trkIT->clearXVhitsCgem();
3335
3336 // --- fill tanl-dz map
3337 int nXVhit = 0;
3338 m_roughTanlDzMap.Reset();
3339 int vote = 3;
3340 //nXVhit = fillHistogram(m_VHoughHitList,&m_roughTanlDzMap,0,vote,trkCandi);
3341 nXVhit = fillHistogram(m_VHoughHitList,&m_roughTanlDzMap,0,vote,&(*trkIT));// fill tanLambda dz map
3342 if(m_debug==5) {
3343 cout<<nXVhit<<" nXVhits filled in the sz Hough map"<<endl;
3344 }
3345 double x_peak(0.), y_peak(0.);
3346 double x_weight(0.), y_weight(0.);
3347 if(nXVhit<3)
3348 {
3349 trkIT->setFlag(3); // not enough V hits
3350 if(m_debug==5) {
3351 cout<<"not enough V hits "<<endl;
3352 cout<<endl;
3353 }
3354 continue;// skip circle with Vhits candidates <3
3355 }
3356 else if(m_nVClusterOnSZmap>0.5*nXVhit)// need to self V-cluster selectionn
3357 {
3358 // FIXME, to be implemented
3359 }
3360 //else {
3361 getWeightedPeak(m_roughTanlDzMap, x_peak, y_peak, x_weight, y_weight);
3362 //cout<<"rough x_peak, y_peak = "<<x_peak<<", "<<y_peak<<endl;
3363 //cout<<"rough x_weight, y_weight = "<<x_weight<<", "<<y_weight<<endl;
3364 //int binx(0),biny(0),binz(0);
3365 //m_roughTanlDzMap.GetMaximumBin(binx,biny,binz);
3366 //int peakHeight = m_roughTanlDzMap.GetBinContent(binx,biny);
3367 //cout<<"peakHeight:"<<peakHeight<<endl;
3368 //cout<<endl;
3369 //cout<<endl;
3370 //x_peak = x_weight;
3371 //y_peak = y_weight;
3372 //-----------------------------------------------------------------
3373 //binning study
3374 //}
3375
3376 double cosTh=x_weight/sqrt(x_weight*x_weight+1);
3377 if(m_debug==5) {
3378 cout<<" cosTh="<<cosTh<<", dz="<<y_weight<<endl;
3379 }
3380 trkIT->setTanl(x_weight);
3381 trkIT->setDz(y_weight);
3382 trkIT->updateHelix();// update pivot and a
3383 int flag = 1;
3384 int charge = trkIT->getCharge();
3385
3386 //int nHot = trkIT->findHot(m_VHoughHitList, flag, charge,3,m_event);
3387 //trkIT->dropRedundentCgemVHits();
3388 //trkIT->setMdcHit( &m_mdcHitCol);
3389 //trkIT->print();
3390 //int l(20);
3391 //int l = Layer; l = 35;
3392 //while(l<36){
3393 // //while(1)
3394 // //cout<<"----------------------------------------------------------------"<<endl;
3395 // //cout<<"----"<<endl;
3396 // double dr = trkIT->dr();
3397 // double phi0 = trkIT->phi0();
3398 // double kappa = trkIT->kappa();
3399 // double dz = trkIT->dz();
3400 // double tanl = trkIT->tanl();
3401 // double cutFactor=1.0;
3402 // if(nXVhit<4) cutFactor=3;
3403 // //int nHot = trkIT->findVHot(m_VHoughHitList,charge,l,cutFactor);
3404 // int nHot = trkIT->findVHot(m_VHoughHitListOnSZmap,charge,l,cutFactor);
3405 // trkIT->dropRedundentCgemVHits();
3406 // if(m_debug)
3407 // {
3408 // cout<<"track id "<<trkIT->getTrkID()<<", maxLayer="<<l<<", nVhits="<<nHot<<endl;
3409 // trkIT->print();
3410 // }
3411 // //cout<<nHot<<endl;
3412 // //trkIT->print();
3413 // vector<HoughHit*> hot = trkIT->getHotList();
3414 // //cout<<"nHot: "<<hot.size()<<endl;
3415 // //cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
3416 // //trkIT->print();
3417 // //trkIT->printHot();
3418 //
3419 // TrkErrCode trkErrCode;
3420 // if(m_fitFlag>1) {
3421 // trkErrCode = trkIT->fitHelix(m_mdcDetector,m_bfield,m_bunchT0,hot,l);
3422 // //trkIT->fitHelix(&myDotsHelixFitter,m_bunchT0*1e9,m_recCgemClusterColBegin);
3423 // }
3424 // //trkIT->print();
3425 // //cout<<"----------------------------------------------------------------"<<endl;
3426 // bool isFitDivergency(false);
3427 // isFitDivergency = isFitDivergency||fabs(trkIT->dr() -dr )>999.;
3428 // isFitDivergency = isFitDivergency||fabs(trkIT->phi0() -phi0 )>999.;
3429 // isFitDivergency = isFitDivergency||fabs(trkIT->kappa() -kappa)>999.;
3430 // isFitDivergency = isFitDivergency||fabs(trkIT->dz() -dz )>999.;
3431 // isFitDivergency = isFitDivergency||fabs(trkIT->tanl() -tanl )>999.;
3432 // if(isFitDivergency){
3433 // trkIT->setFlag(-2);
3434 // if(m_debug)cout<<"helix fit diverged!"<<endl;
3435 // break;
3436 // }
3437 // if(trkErrCode.failure()){
3438 // //if(m_debug)cout<<__FILE__<<" line"<<__LINE__<<":helix fit failure!"<<endl;
3439 // trkIT->setFlag(-1);
3440 // if(m_debug){
3441 // trkErrCode.print(std::cout);cout<<endl;//cout<<endl;
3442 // cout<<"helix fit failed!"<<endl;
3443 // }
3444 // }
3445 // else{
3446 // trkIT->setFlag(0);
3447 // if(m_mcTruth)findMcTrack(&(*trkIT));
3448 // if(m_debug)cout<<"helix fit good!"<<endl;
3449 // }
3450 // if(m_debug)
3451 // {
3452 // cout<<"track info after fit: "<<endl;
3453 // trkIT->print();
3454 // }
3455 //
3456 // l++;
3457 // if(l>m_maxFireLayer)break;
3458 // //break;
3459 // //if(nHot==0)break;
3460 //}// while
3461 //
3462 //if(trkIT->getFlag()!=0)
3463 //{
3464 // //cout<<"trk flag !=0 !"<<endl;"
3465 // continue;
3466 //}
3467 ////cout<<"nHot: "<<nHot<<endl;
3468 ////trkIT->print();
3469 ////trkIT->printHot();
3470 //double dr = trkIT->dr();
3471 //double phi0 = trkIT->phi0();
3472 //double kappa = trkIT->kappa();
3473 //double dz = trkIT->dz();
3474 //double tanl = trkIT->tanl();
3475 //
3476 //double cutFactor=1.0;
3477 //if(nXVhit<4) cutFactor=3;
3478 ////int nHot = trkIT->findVHot(m_VHoughHitList,charge,l,cutFactor);
3479 //int nHot = trkIT->findVHot(m_VHoughHitListOnSZmap,charge,l,cutFactor);
3480 //trkIT->dropRedundentCgemVHits();
3481 //if(m_debug) cout<<"after helix fit, nVhits="<<nHot<<endl;
3482 //vector<HoughHit*> hot = trkIT->getHotList();
3483 //TrkErrCode trkErrCode = trkIT->fitHelix(m_mdcDetector,m_trkContextEv,m_bunchT0,m_mdcHitCol,hot);
3484 //
3485 //bool isFitDivergency(false);
3486 //isFitDivergency = isFitDivergency||fabs(trkIT->dr() -dr )>999.;
3487 //isFitDivergency = isFitDivergency||fabs(trkIT->phi0() -phi0 )>999.;
3488 //isFitDivergency = isFitDivergency||fabs(trkIT->kappa() -kappa)>999.;
3489 //isFitDivergency = isFitDivergency||fabs(trkIT->dz() -dz )>999.;
3490 //isFitDivergency = isFitDivergency||fabs(trkIT->tanl() -tanl )>999.;
3491 //if(isFitDivergency){
3492 // trkIT->setFlag(-2);
3493 // if(m_debug)cout<<"helix fit diverged!"<<endl;
3494 // break;
3495 //}
3496 //if(trkErrCode.failure()){
3497 // //if(m_debug)cout<<__FILE__<<" line"<<__LINE__<<":helix fit failure!"<<endl;
3498 // trkIT->setFlag(-1);
3499 // if(m_debug)cout<<"helix fit failed!"<<endl;
3500 //}
3501 //else{
3502 // trkIT->setFlag(0);
3503 // if(m_mcTruth)findMcTrack(&(*trkIT));
3504 // if(m_debug)cout<<"helix fit good!"<<endl;
3505 //}
3506 //if(trkIT->getFlag()!=0)
3507 //{
3508 // if(m_debug) cout<<"helix flag !=0 !"<<endl;
3509 //}
3510
3511 // --- V-hits selection and helix fit
3512 int helixFitFlag(0);
3513 int nHot_last=0;
3514 int lmax=35;
3515 //while(1)
3516 for(int j=0; j<2; j++)// fit Helix twice
3517 {
3518 double cutFactor=1.0;
3519 if(nXVhit<4) cutFactor=3;
3520 if(fabs(cosTh)>0.8) cutFactor=5;
3521 int nHot = trkIT->findVHot(m_VHoughHitListOnSZmap,charge,lmax,cutFactor); // includes a sz line fit, to be done FIXME
3522 trkIT->dropRedundentCgemVHits();// at most one V-cluster on one layer
3523 // gap check, and remove hits after a big distance // to be done FIXME; could be solved by checking if any axial hit around
3524 if(m_debug==5) trkIT->printHot(3);
3525 helixFitFlag = trkIT->fitHelix(&myDotsHelixFitter,m_bunchT0*1e9,m_recCgemClusterColBegin, m_chi2CutHits);// trkIT's m_dr etc. updated already
3526 if(helixFitFlag==0)
3527 {
3528 trkIT->updateHelix();// update pivot and a
3529 //if(nHot_last!=nHot)
3530 //{
3531 //nHot_last=nHot;
3532 //continue;
3533 //}
3534 //else break;
3535 }
3536 else break;
3537 }
3538 if(helixFitFlag!=0) // if fit fails
3539 {
3540 trkIT->setFlag(helixFitFlag);
3541 if(m_debug==5) {
3542 cout<<"Helix fit failed "<<endl;
3543 cout<<endl;
3544 }
3545 continue; // skip bad helix fit
3546 }
3547 else // if fit successes
3548 {
3549 vector<RecMdcHit> aRecMdcHitVec=myDotsHelixFitter.makeRecMdcHitVec(1);
3550 trkIT->setRecMdcHitVec(aRecMdcHitVec);
3551 //trkIT->setRecMdcHitVec(myDotsHelixFitter.makeRecMdcHitVec(1));
3552 if(m_debug==5) {
3553 cout<<"Helix fit success and aRecMdcHitVec filled "<<endl;
3554 trkIT->printRecMdcHitVec();
3555 cout<<endl;
3556 //trkIT->printHot();
3557 }
3558 }
3559
3560 //cout<<"getId() "<<m_trkContextEv->getId()<<endl;
3561 //trkIT->print();
3562 //cout<<trkIT->dr() -dr <<endl;
3563 //cout<<trkIT->phi0() -phi0 <<endl;
3564 //cout<<trkIT->kappa() -kappa<<endl;
3565 //cout<<trkIT->dz() -dz <<endl;
3566 //cout<<trkIT->tanl() -tanl <<endl;
3567 //trkIT->printHot();
3568 }// loop circles
3569 //cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
3570 //m_debug=false;
3571 return 0;
3572}
3573
3574void HoughFinder::findMcTrack(HoughTrack* track)
3575{
3576 TH1I trkID("track index","",100,0,100);
3577 vector<HoughHit*> hotList = track->getHotList();
3578 for(vector<HoughHit*>::iterator hotIt = hotList.begin(); hotIt != hotList.end(); hotIt++){
3579 if((*hotIt)->getPairHit()!=NULL)trkID.Fill(((*hotIt)->getPairHit()->getTrkID())[0]);
3580 }
3581 int trkid = trkID.GetMaximumBin()-1;
3582 for(vector<HoughTrack>::iterator trkIter = m_mcTrackCol.begin();trkIter!=m_mcTrackCol.end();trkIter++){
3583 if(trkIter->getTrkID()==trkid){
3584 if(m_run<0&&m_mcTruth)track->setMcTrack(&(*trkIter));
3585 break;
3586 }
3587 }
3588}
3589
3590int HoughFinder::nFineBinTanl(double tanl)
3591{
3592}
3593
3594int HoughFinder::nFineBinDz(double tanl)
3595{
3596}
3597
3598void HoughFinder::XVhitCutWindow(double tanl, int ilayer, double charge, double& cut1, double &cut2)
3599{
3600}
3601
3602//if(m_hist)ntuple_hit->write();
3604 MsgStream log(msgSvc(), name());
3605
3606 NTuplePtr nt1(ntupleSvc(), "mdcHoughFinder/hit");
3607 if ( nt1 ){
3608 ntuple_hit= nt1;
3609 } else {
3610 ntuple_hit= ntupleSvc()->book("mdcHoughFinder/hit", CLID_ColumnWiseTuple, "hit");
3611 if(ntuple_hit){
3612 ntuple_hit->addItem("hit_run", m_hit_run);
3613 ntuple_hit->addItem("hit_event", m_hit_event);
3614
3615 ntuple_hit->addItem("hit_nhit", m_hit_nhit, 0, 10000);
3616 ntuple_hit->addItem("hit_hitID", m_hit_nhit, m_hit_hitID);
3617 ntuple_hit->addItem("hit_hitType", m_hit_nhit, m_hit_hitType);
3618 ntuple_hit->addItem("hit_layer", m_hit_nhit, m_hit_layer);
3619 ntuple_hit->addItem("hit_wire", m_hit_nhit, m_hit_wire);
3620 ntuple_hit->addItem("hit_flag", m_hit_nhit, m_hit_flag);
3621 ntuple_hit->addItem("hit_halfCircle", m_hit_nhit, m_hit_halfCircle);
3622 ntuple_hit->addItem("hit_x", m_hit_nhit, m_hit_x);
3623 ntuple_hit->addItem("hit_y", m_hit_nhit, m_hit_y);
3624 ntuple_hit->addItem("hit_z", m_hit_nhit, m_hit_z);
3625 ntuple_hit->addItem("hit_drift", m_hit_nhit, m_hit_drift);
3626
3627 ntuple_hit->addItem("mcHit_hitID", m_hit_nhit, m_mcHit_hitID);
3628 ntuple_hit->addItem("mcHit_hitType", m_hit_nhit, m_mcHit_hitType);
3629 ntuple_hit->addItem("mcHit_layer", m_hit_nhit, m_mcHit_layer);
3630 ntuple_hit->addItem("mcHit_wire", m_hit_nhit, m_mcHit_wire);
3631 ntuple_hit->addItem("mcHit_flag", m_hit_nhit, m_mcHit_flag);
3632 ntuple_hit->addItem("mcHit_halfCircle", m_hit_nhit, m_mcHit_halfCircle);
3633 ntuple_hit->addItem("mcHit_x", m_hit_nhit, m_mcHit_x);
3634 ntuple_hit->addItem("mcHit_y", m_hit_nhit, m_mcHit_y);
3635 ntuple_hit->addItem("mcHit_z", m_hit_nhit, m_mcHit_z);
3636 ntuple_hit->addItem("mcHit_drift", m_hit_nhit, m_mcHit_drift);
3637 } else { log << MSG::ERROR << "Cannot book tuple mdcHoughFinder/hit" <<endmsg;
3638 return StatusCode::FAILURE;
3639 }
3640 }
3641
3642 NTuplePtr nt2(ntupleSvc(), "mdcHoughFinder/track");
3643 if ( nt2 ){
3644 ntuple_track = nt2;
3645 } else {
3646 ntuple_track = ntupleSvc()->book("mdcHoughFinder/track", CLID_ColumnWiseTuple, "track");
3647 if(ntuple_track){
3648 ntuple_track->addItem("trk_run", m_trk_run);
3649 ntuple_track->addItem("trk_event", m_trk_event);
3650 ntuple_track->addItem("trk_nTrack", m_trk_nTrack);
3651 ntuple_track->addItem("trk_trackID", m_trk_trackID);
3652 ntuple_track->addItem("trk_charge", m_trk_charge);
3653 ntuple_track->addItem("trk_flag", m_trk_flag);
3654 ntuple_track->addItem("trk_angle", m_trk_angle);
3655 ntuple_track->addItem("trk_rho", m_trk_rho);
3656 ntuple_track->addItem("trk_dAngle", m_trk_dAngle);
3657 ntuple_track->addItem("trk_dRho", m_trk_dRho);
3658 ntuple_track->addItem("trk_dTanl", m_trk_dTanl);
3659 ntuple_track->addItem("trk_dDz", m_trk_dDz);
3660 ntuple_track->addItem("trk_Xc", m_trk_Xc);
3661 ntuple_track->addItem("trk_Yc", m_trk_Yc);
3662 ntuple_track->addItem("trk_R", m_trk_R);
3663 ntuple_track->addItem("trk_dr", m_trk_dr);
3664 ntuple_track->addItem("trk_phi0", m_trk_phi0);
3665 ntuple_track->addItem("trk_kappa", m_trk_kappa);
3666 ntuple_track->addItem("trk_dz", m_trk_dz);
3667 ntuple_track->addItem("trk_tanl", m_trk_tanl);
3668 ntuple_track->addItem("trk_pxy", m_trk_pxy);
3669 ntuple_track->addItem("trk_px", m_trk_px);
3670 ntuple_track->addItem("trk_py", m_trk_py);
3671 ntuple_track->addItem("trk_pz", m_trk_pz);
3672 ntuple_track->addItem("trk_p", m_trk_p);
3673 ntuple_track->addItem("trk_phi", m_trk_phi);
3674 ntuple_track->addItem("trk_theta", m_trk_theta);
3675 ntuple_track->addItem("trk_cosTheta", m_trk_cosTheta);
3676 ntuple_track->addItem("trk_vx", m_trk_vx);
3677 ntuple_track->addItem("trk_vy", m_trk_vy);
3678 ntuple_track->addItem("trk_vz", m_trk_vz);
3679 ntuple_track->addItem("trk_vr", m_trk_vr);
3680 ntuple_track->addItem("trk_chi2", m_trk_chi2);
3681 ntuple_track->addItem("trk_fiTerm", m_trk_fiTerm);
3682 ntuple_track->addItem("trk_nhit", m_trk_nhit);
3683 ntuple_track->addItem("trk_ncluster", m_trk_ncluster);
3684 ntuple_track->addItem("trk_stat", m_trk_stat);
3685 ntuple_track->addItem("trk_ndof", m_trk_ndof);
3686 ntuple_track->addItem("trk_nster", m_trk_nster);
3687 ntuple_track->addItem("trk_nlayer", m_trk_nlayer);
3688 ntuple_track->addItem("trk_firstLayer", m_trk_firstLayer);
3689 ntuple_track->addItem("trk_lastLayer", m_trk_lastLayer);
3690 ntuple_track->addItem("trk_nCgemXClusters", m_trk_nCgemXClusters);
3691 ntuple_track->addItem("trk_nCgemVClusters", m_trk_nCgemVClusters);
3692
3693 ntuple_track->addItem("trk_nHot", m_trk_nHot, 0, 10000);
3694 ntuple_track->addItem("hot_hitID", m_trk_nHot, m_hot_hitID);
3695 ntuple_track->addItem("hot_hitType", m_trk_nHot, m_hot_hitType);
3696 ntuple_track->addItem("hot_layer", m_trk_nHot, m_hot_layer);
3697 ntuple_track->addItem("hot_wire", m_trk_nHot, m_hot_wire);
3698 ntuple_track->addItem("hot_flag", m_trk_nHot, m_hot_flag);
3699 ntuple_track->addItem("hot_halfCircle", m_trk_nHot, m_hot_halfCircle);
3700 ntuple_track->addItem("hot_x", m_trk_nHot, m_hot_x);
3701 ntuple_track->addItem("hot_y", m_trk_nHot, m_hot_y);
3702 ntuple_track->addItem("hot_z", m_trk_nHot, m_hot_z);
3703 ntuple_track->addItem("hot_drift", m_trk_nHot, m_hot_drift);
3704 ntuple_track->addItem("hot_residual", m_trk_nHot, m_hot_residual);
3705
3706 ntuple_track->addItem("mcHot_hitID", m_trk_nHot, m_mcHot_hitID);
3707 ntuple_track->addItem("mcHot_hitType", m_trk_nHot, m_mcHot_hitType);
3708 ntuple_track->addItem("mcHot_layer", m_trk_nHot, m_mcHot_layer);
3709 ntuple_track->addItem("mcHot_wire", m_trk_nHot, m_mcHot_wire);
3710 ntuple_track->addItem("mcHot_flag", m_trk_nHot, m_mcHot_flag);
3711 ntuple_track->addItem("mcHot_halfCircle", m_trk_nHot, m_mcHot_halfCircle);
3712 ntuple_track->addItem("mcHot_x", m_trk_nHot, m_mcHot_x);
3713 ntuple_track->addItem("mcHot_y", m_trk_nHot, m_mcHot_y);
3714 ntuple_track->addItem("mcHot_z", m_trk_nHot, m_mcHot_z);
3715 ntuple_track->addItem("mcHot_drift", m_trk_nHot, m_mcHot_drift);
3716
3717 ntuple_track->addItem("mcTrk_trackID", m_mcTrk_trackID);
3718 ntuple_track->addItem("mcTrk_charge", m_mcTrk_charge);
3719 ntuple_track->addItem("mcTrk_flag", m_mcTrk_flag);
3720 ntuple_track->addItem("mcTrk_angle", m_mcTrk_angle);
3721 ntuple_track->addItem("mcTrk_rho", m_mcTrk_rho);
3722 ntuple_track->addItem("mcTrk_dAngle", m_mcTrk_dAngle);
3723 ntuple_track->addItem("mcTrk_dRho", m_mcTrk_dRho);
3724 ntuple_track->addItem("mcTrk_dTanl", m_mcTrk_dTanl);
3725 ntuple_track->addItem("mcTrk_dDz", m_mcTrk_dDz);
3726 ntuple_track->addItem("mcTrk_Xc", m_mcTrk_Xc);
3727 ntuple_track->addItem("mcTrk_Yc", m_mcTrk_Yc);
3728 ntuple_track->addItem("mcTrk_R", m_mcTrk_R);
3729 ntuple_track->addItem("mcTrk_dr", m_mcTrk_dr);
3730 ntuple_track->addItem("mcTrk_phi0", m_mcTrk_phi0);
3731 ntuple_track->addItem("mcTrk_kappa", m_mcTrk_kappa);
3732 ntuple_track->addItem("mcTrk_dz", m_mcTrk_dz);
3733 ntuple_track->addItem("mcTrk_tanl", m_mcTrk_tanl);
3734 ntuple_track->addItem("mcTrk_pxy", m_mcTrk_pxy);
3735 ntuple_track->addItem("mcTrk_px", m_mcTrk_px);
3736 ntuple_track->addItem("mcTrk_py", m_mcTrk_py);
3737 ntuple_track->addItem("mcTrk_pz", m_mcTrk_pz);
3738 ntuple_track->addItem("mcTrk_p", m_mcTrk_p);
3739 ntuple_track->addItem("mcTrk_phi", m_mcTrk_phi);
3740 ntuple_track->addItem("mcTrk_theta", m_mcTrk_theta);
3741 ntuple_track->addItem("mcTrk_cosTheta", m_mcTrk_cosTheta);
3742 ntuple_track->addItem("mcTrk_vx", m_mcTrk_vx);
3743 ntuple_track->addItem("mcTrk_vy", m_mcTrk_vy);
3744 ntuple_track->addItem("mcTrk_vz", m_mcTrk_vz);
3745 ntuple_track->addItem("mcTrk_vr", m_mcTrk_vr);
3746 ntuple_track->addItem("mcTrk_chi2", m_mcTrk_chi2);
3747 ntuple_track->addItem("mcTrk_fiTerm", m_mcTrk_fiTerm);
3748 ntuple_track->addItem("mcTrk_nhit", m_mcTrk_nhit);
3749 ntuple_track->addItem("mcTrk_ncluster", m_mcTrk_ncluster);
3750 ntuple_track->addItem("mcTrk_stat", m_mcTrk_stat);
3751 ntuple_track->addItem("mcTrk_ndof", m_mcTrk_ndof);
3752 ntuple_track->addItem("mcTrk_nster", m_mcTrk_nster);
3753 ntuple_track->addItem("mcTrk_nlayer", m_mcTrk_nlayer);
3754 ntuple_track->addItem("mcTrk_firstLayer", m_mcTrk_firstLayer);
3755 ntuple_track->addItem("mcTrk_lastLayer", m_mcTrk_lastLayer);
3756 ntuple_track->addItem("mcTrk_nCgemXClusters", m_mcTrk_nCgemXClusters);
3757 ntuple_track->addItem("mcTrk_nCgemVClusters", m_mcTrk_nCgemVClusters);
3758
3759 ntuple_track->addItem("mcTrk_nHot", m_mcTrk_nHot, 0, 10000);
3760 ntuple_track->addItem("mcTrkHot_hitID", m_mcTrk_nHot, m_mcTrkHot_hitID);
3761 ntuple_track->addItem("mcTrkHot_hitType", m_mcTrk_nHot, m_mcTrkHot_hitType);
3762 ntuple_track->addItem("mcTrkHot_layer", m_mcTrk_nHot, m_mcTrkHot_layer);
3763 ntuple_track->addItem("mcTrkHot_wire", m_mcTrk_nHot, m_mcTrkHot_wire);
3764 ntuple_track->addItem("mcTrkHot_flag", m_mcTrk_nHot, m_mcTrkHot_flag);
3765 ntuple_track->addItem("mcTrkHot_halfCircle", m_mcTrk_nHot, m_mcTrkHot_halfCircle);
3766 ntuple_track->addItem("mcTrkHot_x", m_mcTrk_nHot, m_mcTrkHot_x);
3767 ntuple_track->addItem("mcTrkHot_y", m_mcTrk_nHot, m_mcTrkHot_y);
3768 ntuple_track->addItem("mcTrkHot_z", m_mcTrk_nHot, m_mcTrkHot_z);
3769 ntuple_track->addItem("mcTrkHot_drift", m_mcTrk_nHot, m_mcTrkHot_drift);
3770 } else {
3771 log << MSG::ERROR << "Cannot book tuple mdcHoughFinder/track" <<endmsg;
3772 return StatusCode::FAILURE;
3773 }
3774 }
3775
3776 NTuplePtr nt3(ntupleSvc(), "mdcHoughFinder/event");
3777 if ( nt3 ){
3778 ntuple_event = nt3;
3779 } else {
3780 ntuple_event = ntupleSvc()->book("mdcHoughFinder/event", CLID_ColumnWiseTuple, "event");
3781 if(ntuple_event){
3782 ntuple_event->addItem("evt_run", m_evt_run);
3783 ntuple_event->addItem("evt_event", m_evt_event);
3784 ntuple_event->addItem("evt_nXCluster", m_evt_nXCluster);
3785 ntuple_event->addItem("evt_nVCluster", m_evt_nVCluster);
3786 ntuple_event->addItem("evt_nXVCluster", m_evt_nXVCluster);
3787 ntuple_event->addItem("evt_nCgemCluster", m_evt_nCGEMCluster);
3788 ntuple_event->addItem("evt_nAxialHit", m_evt_nAxialHit);
3789 ntuple_event->addItem("evt_nStereoHit", m_evt_nStereoHit);
3790 ntuple_event->addItem("evt_nODCHit", m_evt_nODCHit);
3791 ntuple_event->addItem("evt_nHit", m_evt_nHit);
3792
3793 ntuple_event->addItem("evt_nTrack", m_evt_nTrack, 0, 100);
3794 ntuple_event->addItem("evtTrk_trackID", m_evt_nTrack, m_evtTrk_trackID);
3795 ntuple_event->addItem("evtTrk_charge", m_evt_nTrack, m_evtTrk_charge);
3796 ntuple_event->addItem("evtTrk_flag", m_evt_nTrack, m_evtTrk_flag);
3797 ntuple_event->addItem("evtTrk_angle", m_evt_nTrack, m_evtTrk_angle);
3798 ntuple_event->addItem("evtTrk_rho", m_evt_nTrack, m_evtTrk_rho);
3799 ntuple_event->addItem("evtTrk_dAngle", m_evt_nTrack, m_evtTrk_dAngle);
3800 ntuple_event->addItem("evtTrk_dRho", m_evt_nTrack, m_evtTrk_dRho);
3801 ntuple_event->addItem("evtTrk_dTanl", m_evt_nTrack, m_evtTrk_dTanl);
3802 ntuple_event->addItem("evtTrk_dDz", m_evt_nTrack, m_evtTrk_dDz);
3803 ntuple_event->addItem("evtTrk_Xc", m_evt_nTrack, m_evtTrk_Xc);
3804 ntuple_event->addItem("evtTrk_Yc", m_evt_nTrack, m_evtTrk_Yc);
3805 ntuple_event->addItem("evtTrk_R", m_evt_nTrack, m_evtTrk_R);
3806 ntuple_event->addItem("evtTrk_dr", m_evt_nTrack, m_evtTrk_dr);
3807 ntuple_event->addItem("evtTrk_phi0", m_evt_nTrack, m_evtTrk_phi0);
3808 ntuple_event->addItem("evtTrk_kappa", m_evt_nTrack, m_evtTrk_kappa);
3809 ntuple_event->addItem("evtTrk_dz", m_evt_nTrack, m_evtTrk_dz);
3810 ntuple_event->addItem("evtTrk_tanl", m_evt_nTrack, m_evtTrk_tanl);
3811 ntuple_event->addItem("evtTrk_pxy", m_evt_nTrack, m_evtTrk_pxy);
3812 ntuple_event->addItem("evtTrk_px", m_evt_nTrack, m_evtTrk_px);
3813 ntuple_event->addItem("evtTrk_py", m_evt_nTrack, m_evtTrk_py);
3814 ntuple_event->addItem("evtTrk_pz", m_evt_nTrack, m_evtTrk_pz);
3815 ntuple_event->addItem("evtTrk_p", m_evt_nTrack, m_evtTrk_p);
3816 ntuple_event->addItem("evtTrk_phi", m_evt_nTrack, m_evtTrk_phi);
3817 ntuple_event->addItem("evtTrk_theta", m_evt_nTrack, m_evtTrk_theta);
3818 ntuple_event->addItem("evtTrk_cosTheta", m_evt_nTrack, m_evtTrk_cosTheta);
3819 ntuple_event->addItem("evtTrk_vx", m_evt_nTrack, m_evtTrk_vx);
3820 ntuple_event->addItem("evtTrk_vy", m_evt_nTrack, m_evtTrk_vy);
3821 ntuple_event->addItem("evtTrk_vz", m_evt_nTrack, m_evtTrk_vz);
3822 ntuple_event->addItem("evtTrk_vr", m_evt_nTrack, m_evtTrk_vr);
3823 ntuple_event->addItem("evtTrk_chi2", m_evt_nTrack, m_evtTrk_chi2);
3824 ntuple_event->addItem("evtTrk_fiTerm", m_evt_nTrack, m_evtTrk_fiTerm);
3825 ntuple_event->addItem("evtTrk_nhit", m_evt_nTrack, m_evtTrk_nhit);
3826 ntuple_event->addItem("evtTrk_ncluster", m_evt_nTrack, m_evtTrk_ncluster);
3827 ntuple_event->addItem("evtTrk_stat", m_evt_nTrack, m_evtTrk_stat);
3828 ntuple_event->addItem("evtTrk_ndof", m_evt_nTrack, m_evtTrk_ndof);
3829 ntuple_event->addItem("evtTrk_nster", m_evt_nTrack, m_evtTrk_nster);
3830 ntuple_event->addItem("evtTrk_nlayer", m_evt_nTrack, m_evtTrk_nlayer);
3831 ntuple_event->addItem("evtTrk_firstLayer", m_evt_nTrack, m_evtTrk_firstLayer);
3832 ntuple_event->addItem("evtTrk_lastLayer", m_evt_nTrack, m_evtTrk_lastLayer);
3833 ntuple_event->addItem("evtTrk_nCgemXClusters", m_evt_nTrack, m_evtTrk_nCgemXClusters);
3834 ntuple_event->addItem("evtTrk_nCgemVClusters", m_evt_nTrack, m_evtTrk_nCgemVClusters);
3835
3836 ntuple_event->addItem("mcEvtTrk_trackID", m_evt_nTrack, m_mcEvtTrk_trackID);
3837 ntuple_event->addItem("mcEvtTrk_charge", m_evt_nTrack, m_mcEvtTrk_charge);
3838 ntuple_event->addItem("mcEvtTrk_flag", m_evt_nTrack, m_mcEvtTrk_flag);
3839 ntuple_event->addItem("mcEvtTrk_angle", m_evt_nTrack, m_mcEvtTrk_angle);
3840 ntuple_event->addItem("mcEvtTrk_rho", m_evt_nTrack, m_mcEvtTrk_rho);
3841 ntuple_event->addItem("mcEvtTrk_dAngle", m_evt_nTrack, m_mcEvtTrk_dAngle);
3842 ntuple_event->addItem("mcEvtTrk_dRho", m_evt_nTrack, m_mcEvtTrk_dRho);
3843 ntuple_event->addItem("mcEvtTrk_dTanl", m_evt_nTrack, m_mcEvtTrk_dTanl);
3844 ntuple_event->addItem("mcEvtTrk_dDz", m_evt_nTrack, m_mcEvtTrk_dDz);
3845 ntuple_event->addItem("mcEvtTrk_Xc", m_evt_nTrack, m_mcEvtTrk_Xc);
3846 ntuple_event->addItem("mcEvtTrk_Yc", m_evt_nTrack, m_mcEvtTrk_Yc);
3847 ntuple_event->addItem("mcEvtTrk_R", m_evt_nTrack, m_mcEvtTrk_R);
3848 ntuple_event->addItem("mcEvtTrk_dr", m_evt_nTrack, m_mcEvtTrk_dr);
3849 ntuple_event->addItem("mcEvtTrk_phi0", m_evt_nTrack, m_mcEvtTrk_phi0);
3850 ntuple_event->addItem("mcEvtTrk_kappa", m_evt_nTrack, m_mcEvtTrk_kappa);
3851 ntuple_event->addItem("mcEvtTrk_dz", m_evt_nTrack, m_mcEvtTrk_dz);
3852 ntuple_event->addItem("mcEvtTrk_tanl", m_evt_nTrack, m_mcEvtTrk_tanl);
3853 ntuple_event->addItem("mcEvtTrk_pxy", m_evt_nTrack, m_mcEvtTrk_pxy);
3854 ntuple_event->addItem("mcEvtTrk_px", m_evt_nTrack, m_mcEvtTrk_px);
3855 ntuple_event->addItem("mcEvtTrk_py", m_evt_nTrack, m_mcEvtTrk_py);
3856 ntuple_event->addItem("mcEvtTrk_pz", m_evt_nTrack, m_mcEvtTrk_pz);
3857 ntuple_event->addItem("mcEvtTrk_p", m_evt_nTrack, m_mcEvtTrk_p);
3858 ntuple_event->addItem("mcEvtTrk_phi", m_evt_nTrack, m_mcEvtTrk_phi);
3859 ntuple_event->addItem("mcEvtTrk_theta", m_evt_nTrack, m_mcEvtTrk_theta);
3860 ntuple_event->addItem("mcEvtTrk_cosTheta", m_evt_nTrack, m_mcEvtTrk_cosTheta);
3861 ntuple_event->addItem("mcEvtTrk_vx", m_evt_nTrack, m_mcEvtTrk_vx);
3862 ntuple_event->addItem("mcEvtTrk_vy", m_evt_nTrack, m_mcEvtTrk_vy);
3863 ntuple_event->addItem("mcEvtTrk_vz", m_evt_nTrack, m_mcEvtTrk_vz);
3864 ntuple_event->addItem("mcEvtTrk_vr", m_evt_nTrack, m_mcEvtTrk_vr);
3865 ntuple_event->addItem("mcEvtTrk_chi2", m_evt_nTrack, m_mcEvtTrk_chi2);
3866 ntuple_event->addItem("mcEvtTrk_fiTerm", m_evt_nTrack, m_mcEvtTrk_fiTerm);
3867 ntuple_event->addItem("mcEvtTrk_nhit", m_evt_nTrack, m_mcEvtTrk_nhit);
3868 ntuple_event->addItem("mcEvtTrk_ncluster", m_evt_nTrack, m_mcEvtTrk_ncluster);
3869 ntuple_event->addItem("mcEvtTrk_stat", m_evt_nTrack, m_mcEvtTrk_stat);
3870 ntuple_event->addItem("mcEvtTrk_ndof", m_evt_nTrack, m_mcEvtTrk_ndof);
3871 ntuple_event->addItem("mcEvtTrk_nster", m_evt_nTrack, m_mcEvtTrk_nster);
3872 ntuple_event->addItem("mcEvtTrk_nlayer", m_evt_nTrack, m_mcEvtTrk_nlayer);
3873 ntuple_event->addItem("mcEvtTrk_firstLayer", m_evt_nTrack, m_mcEvtTrk_firstLayer);
3874 ntuple_event->addItem("mcEvtTrk_lastLayer", m_evt_nTrack, m_mcEvtTrk_lastLayer);
3875 ntuple_event->addItem("mcEvtTrk_nCgemXClusters", m_evt_nTrack, m_mcEvtTrk_nCgemXClusters);
3876 ntuple_event->addItem("mcEvtTrk_nCgemVClusters", m_evt_nTrack, m_mcEvtTrk_nCgemVClusters);
3877 } else {
3878 log << MSG::ERROR << "Cannot book tuple mdcHoughFinder/event" <<endmsg;
3879 return StatusCode::FAILURE;
3880 }
3881 }
3882 return StatusCode::SUCCESS;
3883}
3884
3885int HoughFinder::dumpHit()
3886{
3887 m_hit_run = m_run;
3888 m_hit_event = m_event;
3889 m_hit_nhit = m_houghHitList.size();
3890 int i(0);
3891 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end(); hitIt++){
3892 m_hit_hitID[i] = hitIt->getHitID();
3893 m_hit_hitType[i] = hitIt->getHitType();
3894 m_hit_layer[i] = hitIt->getLayer();
3895 m_hit_wire[i] = hitIt->getWire();
3896 m_hit_flag[i] = hitIt->getFlag();
3897 m_hit_halfCircle[i] = hitIt->getHalfCircle();
3898 m_hit_x[i] = hitIt->getHitPosition().x();
3899 m_hit_y[i] = hitIt->getHitPosition().y();
3900 m_hit_z[i] = hitIt->getHitPosition().z();
3901 m_hit_drift[i] = hitIt->getDriftDist();
3902
3903 if(hitIt->getPairHit()!=NULL){
3904 m_mcHit_hitID[i] = hitIt->getPairHit()->getHitID();
3905 m_mcHit_hitType[i] = hitIt->getPairHit()->getHitType();
3906 m_mcHit_layer[i] = hitIt->getPairHit()->getLayer();
3907 m_mcHit_wire[i] = hitIt->getPairHit()->getWire();
3908 m_mcHit_flag[i] = hitIt->getPairHit()->getFlag();
3909 m_mcHit_halfCircle[i] = hitIt->getPairHit()->getHalfCircle();
3910 m_mcHit_x[i] = hitIt->getPairHit()->getHitPosition().x();
3911 m_mcHit_y[i] = hitIt->getPairHit()->getHitPosition().y();
3912 m_mcHit_z[i] = hitIt->getPairHit()->getHitPosition().z();
3913 m_mcHit_drift[i] = hitIt->getPairHit()->getDriftDist();
3914 }
3915 i++;
3916 }
3917 ntuple_hit->write();
3918 return m_houghHitList.size();
3919}
3920
3921int HoughFinder::dumpHoughTrack()
3922{
3923 if(m_houghTrackList.size()==0)return 0;
3924 m_trk_run = m_run;
3925 m_trk_event = m_event;
3926 m_trk_nTrack = m_houghTrackList.size();
3927 HepPoint3D positionOntrack(999,999,999), positionOnDetector(999,999,999);
3928 for(vector<HoughTrack>::iterator trkIt = m_houghTrackList.begin(); trkIt != m_houghTrackList.end(); trkIt++){
3929 m_trk_trackID = trkIt->getTrkID();
3930 m_trk_charge = trkIt->getCharge();
3931 m_trk_flag = trkIt->getFlag();
3932 m_trk_angle = trkIt->getAngle();
3933 m_trk_rho = trkIt->getRho();
3934 m_trk_dAngle = trkIt->getDAngle();
3935 m_trk_dRho = trkIt->getDRho();
3936 m_trk_dTanl = trkIt->getDTanl();
3937 m_trk_dDz = trkIt->getDDz();
3938 m_trk_Xc = trkIt->center().x();
3939 m_trk_Yc = trkIt->center().y();
3940 m_trk_R = trkIt->radius();
3941 m_trk_dr = trkIt->dr();
3942 m_trk_phi0 = trkIt->phi0();
3943 m_trk_kappa = trkIt->kappa();
3944 m_trk_dz = trkIt->dz();
3945 m_trk_tanl = trkIt->tanl();
3946 m_trk_pxy = trkIt->pt();
3947 m_trk_px = trkIt->momentum(0).x();
3948 m_trk_py = trkIt->momentum(0).y();
3949 m_trk_pz = trkIt->momentum(0).z();
3950 m_trk_p = trkIt->momentum(0).mag();
3951 m_trk_phi = trkIt->direction(0).phi();
3952 m_trk_theta = trkIt->direction(0).theta();
3953 m_trk_cosTheta = cos(trkIt->direction(0).theta());
3954 m_trk_vx = trkIt->x(0).x();
3955 m_trk_vy = trkIt->x(0).y();
3956 m_trk_vz = trkIt->x(0).z();
3957 m_trk_vr = trkIt->x(0).perp();
3958 m_trk_chi2 = trkIt->getChi2();
3959 //m_trk_chi2[i] = trkIt->
3960 //m_trk_fiTerm[i] = trkIt->
3961 //m_trk_nhit[i] = trkIt->
3962 //m_trk_ncluster[i] = trkIt->
3963 //m_trk_stat[i] = trkIt->
3964 //m_trk_ndof[i] = trkIt->
3965 //m_trk_nster[i] = trkIt->
3966 //m_trk_nlayer[i] = trkIt->
3967 //m_trk_firstLayer[i] = trkIt->
3968 //m_trk_lastLayer[i] = trkIt->
3969 //m_trk_nCgemXClusters[i] = trkIt->
3970 //m_trk_nCgemVClusters[i] = trkIt->
3971
3972 vector<HoughHit*> hotList = trkIt->getHotList();
3973 m_trk_nHot = hotList.size();
3974 int i(0);
3975 for(vector<HoughHit*>::iterator hotIt = hotList.begin(); hotIt != hotList.end(); hotIt++){
3976 m_hot_hitID[i] = (*hotIt)->getHitID();
3977 m_hot_hitType[i] = (*hotIt)->getHitType();
3978 m_hot_layer[i] = (*hotIt)->getLayer();
3979 m_hot_wire[i] = (*hotIt)->getWire();
3980 m_hot_flag[i] = (*hotIt)->getFlag();
3981 m_hot_halfCircle[i] = (*hotIt)->getHalfCircle();
3982 m_hot_x[i] = (*hotIt)->getHitPosition().x();
3983 m_hot_y[i] = (*hotIt)->getHitPosition().y();
3984 m_hot_z[i] = (*hotIt)->getHitPosition().z();
3985 m_hot_drift[i] = (*hotIt)->getDriftDist();
3986 m_hot_residual[i] = (*hotIt)->residual(&(*trkIt),positionOntrack, positionOnDetector);
3987
3988 if((*hotIt)->getPairHit()!=NULL){
3989 m_mcHot_hitID[i] = (*hotIt)->getPairHit()->getHitID();
3990 m_mcHot_hitType[i] = (*hotIt)->getPairHit()->getHitType();
3991 m_mcHot_layer[i] = (*hotIt)->getPairHit()->getLayer();
3992 m_mcHot_wire[i] = (*hotIt)->getPairHit()->getWire();
3993 m_mcHot_flag[i] = (*hotIt)->getPairHit()->getFlag();
3994 m_mcHot_halfCircle[i] = (*hotIt)->getPairHit()->getHalfCircle();
3995 m_mcHot_x[i] = (*hotIt)->getPairHit()->getHitPosition().x();
3996 m_mcHot_y[i] = (*hotIt)->getPairHit()->getHitPosition().y();
3997 m_mcHot_z[i] = (*hotIt)->getPairHit()->getHitPosition().z();
3998 m_mcHot_drift[i] = (*hotIt)->getPairHit()->getDriftDist();
3999 }
4000 i++;
4001 }
4002
4003 if(trkIt->getMcTrack()!=NULL){
4004 m_mcTrk_trackID = trkIt->getMcTrack()->getTrkID();
4005 m_mcTrk_charge = trkIt->getMcTrack()->getCharge();
4006 m_mcTrk_flag = trkIt->getMcTrack()->getFlag();
4007 m_mcTrk_angle = trkIt->getMcTrack()->getAngle();
4008 m_mcTrk_rho = trkIt->getMcTrack()->getRho();
4009 m_mcTrk_dAngle = trkIt->getMcTrack()->getDAngle();
4010 m_mcTrk_dRho = trkIt->getMcTrack()->getDRho();
4011 m_mcTrk_dTanl = trkIt->getMcTrack()->getDTanl();
4012 m_mcTrk_dDz = trkIt->getMcTrack()->getDDz();
4013 m_mcTrk_Xc = trkIt->getMcTrack()->center().x();
4014 m_mcTrk_Yc = trkIt->getMcTrack()->center().y();
4015 m_mcTrk_R = trkIt->getMcTrack()->radius();
4016 m_mcTrk_dr = trkIt->getMcTrack()->dr();
4017 m_mcTrk_phi0 = trkIt->getMcTrack()->phi0();
4018 m_mcTrk_kappa = trkIt->getMcTrack()->kappa();
4019 m_mcTrk_dz = trkIt->getMcTrack()->dz();
4020 m_mcTrk_tanl = trkIt->getMcTrack()->tanl();
4021 m_mcTrk_pxy = trkIt->getMcTrack()->pt();
4022 m_mcTrk_px = trkIt->getMcTrack()->momentum(0).x();
4023 m_mcTrk_py = trkIt->getMcTrack()->momentum(0).y();
4024 m_mcTrk_pz = trkIt->getMcTrack()->momentum(0).z();
4025 m_mcTrk_p = trkIt->getMcTrack()->momentum(0).mag();
4026 m_mcTrk_phi = trkIt->getMcTrack()->direction(0).phi();
4027 m_mcTrk_theta = trkIt->getMcTrack()->direction(0).theta();
4028 m_mcTrk_cosTheta = cos(trkIt->getMcTrack()->direction(0).theta());
4029 m_mcTrk_vx = trkIt->getMcTrack()->x(0).x();
4030 m_mcTrk_vy = trkIt->getMcTrack()->x(0).y();
4031 m_mcTrk_vz = trkIt->getMcTrack()->x(0).z();
4032 m_mcTrk_vr = trkIt->getMcTrack()->x(0).perp();
4033 //m_mcTrk_chi2 = trkIt->getMcTrack()->
4034 //m_mcTrk_fiTerm = trkIt->getMcTrack()->
4035 //m_mcTrk_nhit = trkIt->getMcTrack()->
4036 //m_mcTrk_ncluster = trkIt->getMcTrack()->
4037 //m_mcTrk_stat = trkIt->getMcTrack()->
4038 //m_mcTrk_ndof = trkIt->getMcTrack()->
4039 //m_mcTrk_nster = trkIt->getMcTrack()->
4040 //m_mcTrk_nlayer = trkIt->getMcTrack()->
4041 //m_mcTrk_firstLayer = trkIt->getMcTrack()->
4042 //m_mcTrk_lastLayer = trkIt->getMcTrack()->
4043 //m_mcTrk_nCgemXClusters = trkIt->getMcTrack()->
4044 //m_mcTrk_nCgemVClusters = trkIt->getMcTrack()->
4045
4046 vector<HoughHit*> mcHotList = trkIt->getMcTrack()->getHotList();
4047 m_mcTrk_nHot = mcHotList.size();
4048 int j(0);
4049 for(vector<HoughHit*>::iterator mcHotIt = mcHotList.begin(); mcHotIt != mcHotList.end(); mcHotIt++){
4050 m_mcTrkHot_hitID[j] = (*mcHotIt)->getHitID();
4051 m_mcTrkHot_hitType[j] = (*mcHotIt)->getHitType();
4052 m_mcTrkHot_layer[j] = (*mcHotIt)->getLayer();
4053 m_mcTrkHot_wire[j] = (*mcHotIt)->getWire();
4054 m_mcTrkHot_flag[j] = (*mcHotIt)->getFlag();
4055 m_mcTrkHot_halfCircle[j] = (*mcHotIt)->getHalfCircle();
4056 m_mcTrkHot_x[j] = (*mcHotIt)->getHitPosition().x();
4057 m_mcTrkHot_y[j] = (*mcHotIt)->getHitPosition().y();
4058 m_mcTrkHot_z[j] = (*mcHotIt)->getHitPosition().z();
4059 m_mcTrkHot_drift[j] = (*mcHotIt)->getDriftDist();
4060 j++;
4061 }
4062 }
4063 ntuple_track->write();
4064 }
4065 return m_houghTrackList.size();
4066}
4067
4068int HoughFinder::dumpHoughEvent()
4069{
4070 if(m_houghTrackList.size()==0)return 0;
4071 m_evt_run = m_run;
4072 m_evt_event = m_event;
4073 m_evt_nTrack = m_houghTrackList.size();
4074 int i(0);
4075 for(vector<HoughTrack>::iterator trkIt = m_houghTrackList.begin(); trkIt != m_houghTrackList.end(); trkIt++){
4076
4077 m_evtTrk_trackID[i] = trkIt->getTrkID();
4078 m_evtTrk_charge[i] = trkIt->getCharge();
4079 m_evtTrk_flag[i] = trkIt->getFlag();
4080 m_evtTrk_angle[i] = trkIt->getAngle();
4081 m_evtTrk_rho[i] = trkIt->getRho();
4082 m_evtTrk_dAngle[i] = trkIt->getDAngle();
4083 m_evtTrk_dRho[i] = trkIt->getDRho();
4084 m_evtTrk_dTanl[i] = trkIt->getDTanl();
4085 m_evtTrk_dDz[i] = trkIt->getDDz();
4086 m_evtTrk_Xc[i] = trkIt->center().x();
4087 m_evtTrk_Yc[i] = trkIt->center().y();
4088 m_evtTrk_R[i] = trkIt->radius();
4089 m_evtTrk_dr[i] = trkIt->dr();
4090 m_evtTrk_phi0[i] = trkIt->phi0();
4091 m_evtTrk_kappa[i] = trkIt->kappa();
4092 m_evtTrk_dz[i] = trkIt->dz();
4093 m_evtTrk_tanl[i] = trkIt->tanl();
4094 m_evtTrk_pxy[i] = trkIt->pt();
4095 m_evtTrk_px[i] = trkIt->momentum(0).x();
4096 m_evtTrk_py[i] = trkIt->momentum(0).y();
4097 m_evtTrk_pz[i] = trkIt->momentum(0).z();
4098 m_evtTrk_p[i] = trkIt->momentum(0).mag();
4099 m_evtTrk_phi[i] = trkIt->direction(0).phi();
4100 m_evtTrk_theta[i] = trkIt->direction(0).theta();
4101 m_evtTrk_cosTheta[i] = cos(trkIt->direction(0).theta());
4102 m_evtTrk_vx[i] = trkIt->x(0).x();
4103 m_evtTrk_vy[i] = trkIt->x(0).y();
4104 m_evtTrk_vz[i] = trkIt->x(0).z();
4105 m_evtTrk_vr[i] = trkIt->x(0).perp();
4106
4107 //m_evtTrk_chi2[i] = trkIt->
4108 //m_evtTrk_fiTerm[i] = trkIt->
4109 //m_evtTrk_nhit[i] = trkIt->
4110 //m_evtTrk_ncluster[i] = trkIt->
4111 //m_evtTrk_stat[i] = trkIt->
4112 //m_evtTrk_ndof[i] = trkIt->
4113 //m_evtTrk_nster[i] = trkIt->
4114 //m_evtTrk_nlayer[i] = trkIt->
4115 //m_evtTrk_firstLayer[i] = trkIt->
4116 //m_evtTrk_lastLayer[i] = trkIt->
4117 //m_evtTrk_nCgemXClusters[i] = trkIt->
4118 //m_evtTrk_nCgemVClusters[i] = trkIt->
4119 if(trkIt->getMcTrack()!=NULL){
4120 m_mcEvtTrk_trackID[i] = trkIt->getMcTrack()->getTrkID();
4121 m_mcEvtTrk_charge[i] = trkIt->getMcTrack()->getCharge();
4122 m_mcEvtTrk_flag[i] = trkIt->getMcTrack()->getFlag();
4123 m_mcEvtTrk_angle[i] = trkIt->getMcTrack()->getAngle();
4124 m_mcEvtTrk_rho[i] = trkIt->getMcTrack()->getRho();
4125 m_mcEvtTrk_dAngle[i] = trkIt->getMcTrack()->getDAngle();
4126 m_mcEvtTrk_dRho[i] = trkIt->getMcTrack()->getDRho();
4127 m_mcEvtTrk_dTanl[i] = trkIt->getMcTrack()->getDTanl();
4128 m_mcEvtTrk_dDz[i] = trkIt->getMcTrack()->getDDz();
4129 m_mcEvtTrk_Xc[i] = trkIt->getMcTrack()->center().x();
4130 m_mcEvtTrk_Yc[i] = trkIt->getMcTrack()->center().y();
4131 m_mcEvtTrk_R[i] = trkIt->getMcTrack()->radius();
4132 m_mcEvtTrk_dr[i] = trkIt->getMcTrack()->dr();
4133 m_mcEvtTrk_phi0[i] = trkIt->getMcTrack()->phi0();
4134 m_mcEvtTrk_kappa[i] = trkIt->getMcTrack()->kappa();
4135 m_mcEvtTrk_dz[i] = trkIt->getMcTrack()->dz();
4136 m_mcEvtTrk_tanl[i] = trkIt->getMcTrack()->tanl();
4137 m_mcEvtTrk_pxy[i] = trkIt->getMcTrack()->pt();
4138 m_mcEvtTrk_px[i] = trkIt->getMcTrack()->momentum(0).x();
4139 m_mcEvtTrk_py[i] = trkIt->getMcTrack()->momentum(0).y();
4140 m_mcEvtTrk_pz[i] = trkIt->getMcTrack()->momentum(0).z();
4141 m_mcEvtTrk_p[i] = trkIt->getMcTrack()->momentum(0).mag();
4142 m_mcEvtTrk_phi[i] = trkIt->getMcTrack()->direction(0).phi();
4143 m_mcEvtTrk_theta[i] = trkIt->getMcTrack()->direction(0).theta();
4144 m_mcEvtTrk_cosTheta[i] = cos(trkIt->getMcTrack()->direction(0).theta());
4145 m_mcEvtTrk_vx[i] = trkIt->getMcTrack()->x(0).x();
4146 m_mcEvtTrk_vy[i] = trkIt->getMcTrack()->x(0).y();
4147 m_mcEvtTrk_vz[i] = trkIt->getMcTrack()->x(0).z();
4148 m_mcEvtTrk_vr[i] = trkIt->getMcTrack()->x(0).perp();
4149 //m_mcEvtTrk_chi2[i] = trkIt->getMcTrack()->
4150 //m_mcEvtTrk_fiTerm[i] = trkIt->getMcTrack()->
4151 //m_mcEvtTrk_nhit[i] = trkIt->getMcTrack()->
4152 //m_mcEvtTrk_ncluster[i] = trkIt->getMcTrack()->
4153 //m_mcEvtTrk_stat[i] = trkIt->getMcTrack()->
4154 //m_mcEvtTrk_ndof[i] = trkIt->getMcTrack()->
4155 //m_mcEvtTrk_nster[i] = trkIt->getMcTrack()->
4156 //m_mcEvtTrk_nlayer[i] = trkIt->getMcTrack()->
4157 //m_mcEvtTrk_firstLayer[i] = trkIt->getMcTrack()->
4158 //m_mcEvtTrk_lastLayer[i] = trkIt->getMcTrack()->
4159 //m_mcEvtTrk_nCgemXClusters[i] = trkIt->getMcTrack()->
4160 //m_mcEvtTrk_nCgemVClusters[i] = trkIt->getMcTrack()->
4161 }
4162 i++;
4163 }
4164 ntuple_event->write();
4165 return m_houghTrackList.size();
4166}
4167
4168int HoughFinder::dumpTdsTrack()
4169{
4170 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
4171 if(!recMdcTrackCol)return 0;
4172 m_evt_run = m_run;
4173 m_evt_event = m_event;
4174 m_evt_nTrack = recMdcTrackCol->size();
4175 for(RecMdcTrackCol::iterator iter = recMdcTrackCol->begin();iter!=recMdcTrackCol->end();iter++){
4176 m_trk_trackID = (*iter)->trackId() ;
4177 m_trk_charge = (*iter)->charge() ;
4178 //m_trk_flag = (*iter)->
4179 //m_trk_angle = (*iter)->
4180 //m_trk_rho = (*iter)->
4181 //m_trk_dAngle = (*iter)->
4182 //m_trk_dRho = (*iter)->
4183 //m_trk_dTanl = (*iter)->
4184 //m_trk_dDz = (*iter)->
4185 //m_trk_Xc = (*iter)->
4186 //m_trk_Yc = (*iter)->
4187 //m_trk_R = (*iter)->
4188 m_trk_dr = (*iter)->helix(0) ;
4189 m_trk_phi0 = (*iter)->helix(1) ;
4190 m_trk_kappa = (*iter)->helix(2) ;
4191 m_trk_dz = (*iter)->helix(3) ;
4192 m_trk_tanl = (*iter)->helix(4) ;
4193 m_trk_pxy = (*iter)->pxy() ;
4194 m_trk_px = (*iter)->px() ;
4195 m_trk_py = (*iter)->py() ;
4196 m_trk_pz = (*iter)->pz() ;
4197 m_trk_p = (*iter)->p() ;
4198 m_trk_phi = (*iter)->theta() ;
4199 m_trk_theta = (*iter)->phi() ;
4200 m_trk_cosTheta = cos((*iter)->theta()) ;
4201 m_trk_vx = (*iter)->x() ;
4202 m_trk_vy = (*iter)->y() ;
4203 m_trk_vz = (*iter)->z() ;
4204 m_trk_vr = (*iter)->r() ;
4205 m_trk_chi2 = (*iter)->chi2() ;
4206 m_trk_fiTerm = (*iter)->getFiTerm() ;
4207 m_trk_nhit = (*iter)->getNhits() ;
4208 m_trk_ncluster = (*iter)->getNcluster() ;
4209 m_trk_stat = (*iter)->stat() ;
4210 m_trk_ndof = (*iter)->ndof() ;
4211 m_trk_nster = (*iter)->nster() ;
4212 m_trk_nlayer = (*iter)->nlayer() ;
4213 m_trk_firstLayer = (*iter)->firstLayer() ;
4214 m_trk_lastLayer = (*iter)->lastLayer() ;
4215 m_trk_nCgemXClusters = (*iter)->nCgemXCluster();
4216 m_trk_nCgemVClusters = (*iter)->nCgemVCluster();
4217
4218 HitRefVec hitRefVec = (*iter)->getVecHits();
4219 HitRefVec::iterator hotIt = hitRefVec.begin();
4220 ClusterRefVec clusterRefVec = (*iter)->getVecClusters();
4221 ClusterRefVec::iterator clusterIt = clusterRefVec.begin();
4222 m_trk_nHot = clusterRefVec.size() + hitRefVec.size();
4223 int i(0);
4224 for(clusterIt=clusterRefVec.begin();clusterIt!=clusterRefVec.end();clusterIt++){
4225 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end(); hitIt++){
4226 if(hitIt->getHitType()!=HoughHit::CGEMHIT)continue;
4227 if((*clusterIt)->getclusterid()==(hitIt)->getCgemCluster()->getclusterid()){
4228 m_hot_hitID[i] = (hitIt)->getHitID();
4229 m_hot_hitType[i] = (hitIt)->getHitType();
4230 m_hot_layer[i] = (hitIt)->getLayer();
4231 m_hot_wire[i] = (hitIt)->getWire();
4232 m_hot_flag[i] = (hitIt)->getFlag();
4233 m_hot_halfCircle[i] = (hitIt)->getHalfCircle();
4234 m_hot_x[i] = (hitIt)->getHitPosition().x();
4235 m_hot_y[i] = (hitIt)->getHitPosition().y();
4236 m_hot_z[i] = (hitIt)->getHitPosition().z();
4237 m_hot_drift[i] = (hitIt)->getDriftDist();
4238 m_hot_residual[i] = -999;
4239
4240 if((hitIt)->getPairHit()!=NULL){
4241 m_mcHot_hitID[i] = (hitIt)->getPairHit()->getHitID();
4242 m_mcHot_hitType[i] = (hitIt)->getPairHit()->getHitType();
4243 m_mcHot_layer[i] = (hitIt)->getPairHit()->getLayer();
4244 m_mcHot_wire[i] = (hitIt)->getPairHit()->getWire();
4245 m_mcHot_flag[i] = (hitIt)->getPairHit()->getFlag();
4246 m_mcHot_halfCircle[i] = (hitIt)->getPairHit()->getHalfCircle();
4247 m_mcHot_x[i] = (hitIt)->getPairHit()->getHitPosition().x();
4248 m_mcHot_y[i] = (hitIt)->getPairHit()->getHitPosition().y();
4249 m_mcHot_z[i] = (hitIt)->getPairHit()->getHitPosition().z();
4250 m_mcHot_drift[i] = (hitIt)->getPairHit()->getDriftDist();
4251 }
4252 i++;
4253 }
4254 }
4255 }
4256 for(hotIt=hitRefVec.begin();hotIt!=hitRefVec.end();hotIt++){
4257 int layer = MdcID::layer((*hotIt)->getMdcId());
4258 int wire = MdcID::wire((*hotIt)->getMdcId());
4259 for(HitVector_Iterator hitIt = m_houghHitList.begin(); hitIt != m_houghHitList.end(); hitIt++){
4260 if(hitIt->getHitType()!=HoughHit::MDCHIT)continue;
4261 if(layer == (hitIt)->getLayer() && wire == (hitIt)->getWire()){
4262 m_hot_hitID[i] = (hitIt)->getHitID();
4263 m_hot_hitType[i] = (hitIt)->getHitType();
4264 m_hot_layer[i] = (hitIt)->getLayer();
4265 m_hot_wire[i] = (hitIt)->getWire();
4266 m_hot_flag[i] = (hitIt)->getFlag();
4267 m_hot_halfCircle[i] = (hitIt)->getHalfCircle();
4268 m_hot_x[i] = (hitIt)->getHitPosition().x();
4269 m_hot_y[i] = (hitIt)->getHitPosition().y();
4270 m_hot_z[i] = (hitIt)->getHitPosition().z();
4271 m_hot_drift[i] = (hitIt)->getDriftDist();
4272 m_hot_residual[i] = 999;
4273
4274 if((hitIt)->getPairHit()!=NULL){
4275 m_mcHot_hitID[i] = (hitIt)->getPairHit()->getHitID();
4276 m_mcHot_hitType[i] = (hitIt)->getPairHit()->getHitType();
4277 m_mcHot_layer[i] = (hitIt)->getPairHit()->getLayer();
4278 m_mcHot_wire[i] = (hitIt)->getPairHit()->getWire();
4279 m_mcHot_flag[i] = (hitIt)->getPairHit()->getFlag();
4280 m_mcHot_halfCircle[i] = (hitIt)->getPairHit()->getHalfCircle();
4281 m_mcHot_x[i] = (hitIt)->getPairHit()->getHitPosition().x();
4282 m_mcHot_y[i] = (hitIt)->getPairHit()->getHitPosition().y();
4283 m_mcHot_z[i] = (hitIt)->getPairHit()->getHitPosition().z();
4284 m_mcHot_drift[i] = (hitIt)->getPairHit()->getDriftDist();
4285 }
4286 }
4287 }
4288 i++;
4289 }
4290
4291 int maxSameHitNumber(0);
4292 vector<HoughTrack>::iterator sameTrkIt = m_mcTrackCol.end();
4293 vector<HoughTrack>::iterator trkIter = m_mcTrackCol.begin();
4294 for(;trkIter!=m_mcTrackCol.end();trkIter++){
4295 int sameHitNumber(0);
4296 vector<HoughHit*> hitList = trkIter->getHotList();
4297 for(vector<HoughHit*>::iterator mchotIt = hitList.begin(); mchotIt != hitList.end();mchotIt++){
4298 if((*mchotIt)->getHitType()==HoughHit::CGEMHIT){
4299 for(clusterIt=clusterRefVec.begin();clusterIt!=clusterRefVec.end();clusterIt++){
4300 if((*clusterIt)->getclusterid()==(*mchotIt)->getCgemCluster()->getclusterid()){
4301 sameHitNumber++;
4302 }
4303 }
4304 }else if((*mchotIt)->getHitType()==HoughHit::MDCHIT){
4305 for(hotIt=hitRefVec.begin();hotIt!=hitRefVec.end();hotIt++){
4306 int layer = MdcID::layer((*hotIt)->getMdcId());
4307 int wire = MdcID::wire((*hotIt)->getMdcId());
4308 if(layer == (*mchotIt)->getLayer() && wire == (*mchotIt)->getWire()){
4309 sameHitNumber++;
4310 }
4311 }
4312 }
4313 }
4314 if(sameHitNumber>maxSameHitNumber){
4315 maxSameHitNumber = sameHitNumber;
4316 sameTrkIt = trkIter;
4317 }
4318
4319 }
4320
4321 if(sameTrkIt!=m_mcTrackCol.end()){
4322 m_mcTrk_trackID = sameTrkIt->getTrkID();
4323 m_mcTrk_charge = sameTrkIt->getCharge();
4324 m_mcTrk_flag = sameTrkIt->getFlag();
4325 m_mcTrk_angle = sameTrkIt->getAngle();
4326 m_mcTrk_rho = sameTrkIt->getRho();
4327 m_mcTrk_dAngle = sameTrkIt->getDAngle();
4328 m_mcTrk_dRho = sameTrkIt->getDRho();
4329 m_mcTrk_dTanl = sameTrkIt->getDTanl();
4330 m_mcTrk_dDz = sameTrkIt->getDDz();
4331 m_mcTrk_Xc = sameTrkIt->center().x();
4332 m_mcTrk_Yc = sameTrkIt->center().y();
4333 m_mcTrk_R = sameTrkIt->radius();
4334 m_mcTrk_dr = sameTrkIt->dr();
4335 m_mcTrk_phi0 = sameTrkIt->phi0();
4336 m_mcTrk_kappa = sameTrkIt->kappa();
4337 m_mcTrk_dz = sameTrkIt->dz();
4338 m_mcTrk_tanl = sameTrkIt->tanl();
4339 m_mcTrk_pxy = sameTrkIt->pt();
4340 m_mcTrk_px = sameTrkIt->momentum(0).x();
4341 m_mcTrk_py = sameTrkIt->momentum(0).y();
4342 m_mcTrk_pz = sameTrkIt->momentum(0).z();
4343 m_mcTrk_p = sameTrkIt->momentum(0).mag();
4344 m_mcTrk_phi = sameTrkIt->direction(0).phi();
4345 m_mcTrk_theta = sameTrkIt->direction(0).theta();
4346 m_mcTrk_cosTheta = cos(sameTrkIt->direction(0).theta());
4347 m_mcTrk_vx = sameTrkIt->x(0).x();
4348 m_mcTrk_vy = sameTrkIt->x(0).y();
4349 m_mcTrk_vz = sameTrkIt->x(0).z();
4350 m_mcTrk_vr = sameTrkIt->x(0).perp();
4351 //m_mcTrk_chi2 = sameTrkIt->getChi2();
4352 //m_mcTrk_fiTerm = sameTrkIt->
4353 //m_mcTrk_nhit = (sameTrkIt->getHotList()).size();
4354 //m_mcTrk_ncluster = sameTrkIt->
4355 //m_mcTrk_stat = sameTrkIt->
4356 //m_mcTrk_ndof = sameTrkIt->
4357 //m_mcTrk_nster = sameTrkIt->
4358 //m_mcTrk_nlayer = sameTrkIt->
4359 //m_mcTrk_firstLayer = sameTrkIt->
4360 //m_mcTrk_lastLayer = sameTrkIt->
4361 //m_mcTrk_nC emXClusters = sameTrkIt->
4362 //m_mcTrk_nCgemVClusters = sameTrkIt->
4363 vector<HoughHit*> mcHotList = sameTrkIt->getHotList();
4364 int j(0);
4365 for(vector<HoughHit*>::iterator mcHotIt = mcHotList.begin(); mcHotIt != mcHotList.end(); mcHotIt++){
4366 m_mcTrkHot_hitID[j] = (*mcHotIt)->getHitID();
4367 m_mcTrkHot_hitType[j] = (*mcHotIt)->getHitType();
4368 m_mcTrkHot_layer[j] = (*mcHotIt)->getLayer();
4369 m_mcTrkHot_wire[j] = (*mcHotIt)->getWire();
4370 m_mcTrkHot_flag[j] = (*mcHotIt)->getFlag();
4371 m_mcTrkHot_halfCircle[j] = (*mcHotIt)->getHalfCircle();
4372 m_mcTrkHot_x[j] = (*mcHotIt)->getHitPosition().x();
4373 m_mcTrkHot_y[j] = (*mcHotIt)->getHitPosition().y();
4374 m_mcTrkHot_z[j] = (*mcHotIt)->getHitPosition().z();
4375 m_mcTrkHot_drift[j] = (*mcHotIt)->getDriftDist();
4376 j++;
4377 }
4378 }
4379 ntuple_track->write();
4380 }
4381 return recMdcTrackCol->size();
4382}
4383
4384int HoughFinder::dumpTdsEvent()
4385{
4386 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
4387 if(!recMdcTrackCol)return 0;
4388 m_evt_run = m_run;
4389 m_evt_event = m_event;
4390 m_evt_nTrack = recMdcTrackCol->size();
4391 int i(0);
4392 for(RecMdcTrackCol::iterator iter = recMdcTrackCol->begin();iter!=recMdcTrackCol->end();iter++){
4393 m_evtTrk_trackID[i] = (*iter)->trackId() ;
4394 m_evtTrk_charge[i] = (*iter)->charge() ;
4395 //m_evtTrk_flag[i] = (*iter)->
4396 //m_evtTrk_angle[i] = (*iter)->
4397 //m_evtTrk_rho[i] = (*iter)->
4398 //m_evtTrk_dAngle[i] = (*iter)->
4399 //m_evtTrk_dRho[i] = (*iter)->
4400 //m_evtTrk_dTanl[i] = (*iter)->
4401 //m_evtTrk_dDz[i] = (*iter)->
4402 //m_evtTrk_Xc[i] = (*iter)->
4403 //m_evtTrk_Yc[i] = (*iter)->
4404 //m_evtTrk_R[i] = (*iter)->
4405 m_evtTrk_dr[i] = (*iter)->helix(0) ;
4406 m_evtTrk_phi0[i] = (*iter)->helix(1) ;
4407 m_evtTrk_kappa[i] = (*iter)->helix(2) ;
4408 m_evtTrk_dz[i] = (*iter)->helix(3) ;
4409 m_evtTrk_tanl[i] = (*iter)->helix(4) ;
4410 m_evtTrk_pxy[i] = (*iter)->pxy() ;
4411 m_evtTrk_px[i] = (*iter)->px() ;
4412 m_evtTrk_py[i] = (*iter)->py() ;
4413 m_evtTrk_pz[i] = (*iter)->pz() ;
4414 m_evtTrk_p[i] = (*iter)->p() ;
4415 m_evtTrk_phi[i] = (*iter)->theta() ;
4416 m_evtTrk_theta[i] = (*iter)->phi() ;
4417 m_evtTrk_cosTheta[i] = cos((*iter)->theta()) ;
4418 m_evtTrk_vx[i] = (*iter)->x() ;
4419 m_evtTrk_vy[i] = (*iter)->y() ;
4420 m_evtTrk_vz[i] = (*iter)->z() ;
4421 m_evtTrk_vr[i] = (*iter)->r() ;
4422 m_evtTrk_chi2[i] = (*iter)->chi2() ;
4423 m_evtTrk_fiTerm[i] = (*iter)->getFiTerm() ;
4424 m_evtTrk_nhit[i] = (*iter)->getNhits() ;
4425 m_evtTrk_ncluster[i] = (*iter)->getNcluster() ;
4426 m_evtTrk_stat[i] = (*iter)->stat() ;
4427 m_evtTrk_ndof[i] = (*iter)->ndof() ;
4428 m_evtTrk_nster[i] = (*iter)->nster() ;
4429 m_evtTrk_nlayer[i] = (*iter)->nlayer() ;
4430 m_evtTrk_firstLayer[i] = (*iter)->firstLayer() ;
4431 m_evtTrk_lastLayer[i] = (*iter)->lastLayer() ;
4432 m_evtTrk_nCgemXClusters[i] = (*iter)->nCgemXCluster();
4433 m_evtTrk_nCgemVClusters[i] = (*iter)->nCgemVCluster();
4434
4435 HitRefVec hitRefVec = (*iter)->getVecHits();
4436 HitRefVec::iterator hitIt = hitRefVec.begin();
4437 ClusterRefVec clusterRefVec = (*iter)->getVecClusters();
4438 ClusterRefVec::iterator clusterIt = clusterRefVec.begin();
4439
4440 int maxSameHitNumber(0);
4441 vector<HoughTrack>::iterator sameTrkIt = m_mcTrackCol.end();
4442 vector<HoughTrack>::iterator trkIter = m_mcTrackCol.begin();
4443 for(;trkIter!=m_mcTrackCol.end();trkIter++){
4444 int sameHitNumber(0);
4445 vector<HoughHit*> hitList = trkIter->getHotList();
4446 for(vector<HoughHit*>::iterator hotIt = hitList.begin(); hotIt != hitList.end();hotIt++){
4447 if((*hotIt)->getHitType()==HoughHit::CGEMHIT){
4448 for(;clusterIt!=clusterRefVec.end();clusterIt++){
4449 if((*clusterIt)->getclusterid()==(*hotIt)->getCgemCluster()->getclusterid()){
4450 sameHitNumber++;
4451 }
4452 }
4453 }else if((*hotIt)->getHitType()==HoughHit::MDCHIT){
4454 for(;hitIt!=hitRefVec.end();hitIt++){
4455 int layer = MdcID::layer((*hitIt)->getMdcId());
4456 int wire = MdcID::wire((*hitIt)->getMdcId());
4457 if(layer == (*hotIt)->getLayer() && wire == (*hotIt)->getWire()){
4458 sameHitNumber++;
4459 }
4460 }
4461 }
4462 }
4463 if(sameHitNumber>maxSameHitNumber){
4464 maxSameHitNumber = sameHitNumber;
4465 sameTrkIt = trkIter;
4466 }
4467
4468 }
4469
4470 if(sameTrkIt!=m_mcTrackCol.end()){
4471 m_mcEvtTrk_trackID[i] = sameTrkIt->getTrkID();
4472 m_mcEvtTrk_charge[i] = sameTrkIt->getCharge();
4473 m_mcEvtTrk_flag[i] = sameTrkIt->getFlag();
4474 m_mcEvtTrk_angle[i] = sameTrkIt->getAngle();
4475 m_mcEvtTrk_rho[i] = sameTrkIt->getRho();
4476 m_mcEvtTrk_dAngle[i] = sameTrkIt->getDAngle();
4477 m_mcEvtTrk_dRho[i] = sameTrkIt->getDRho();
4478 m_mcEvtTrk_dTanl[i] = sameTrkIt->getDTanl();
4479 m_mcEvtTrk_dDz[i] = sameTrkIt->getDDz();
4480 m_mcEvtTrk_Xc[i] = sameTrkIt->center().x();
4481 m_mcEvtTrk_Yc[i] = sameTrkIt->center().y();
4482 m_mcEvtTrk_R[i] = sameTrkIt->radius();
4483 m_mcEvtTrk_dr[i] = sameTrkIt->dr();
4484 m_mcEvtTrk_phi0[i] = sameTrkIt->phi0();
4485 m_mcEvtTrk_kappa[i] = sameTrkIt->kappa();
4486 m_mcEvtTrk_dz[i] = sameTrkIt->dz();
4487 m_mcEvtTrk_tanl[i] = sameTrkIt->tanl();
4488 m_mcEvtTrk_pxy[i] = sameTrkIt->pt();
4489 m_mcEvtTrk_px[i] = sameTrkIt->momentum(0).x();
4490 m_mcEvtTrk_py[i] = sameTrkIt->momentum(0).y();
4491 m_mcEvtTrk_pz[i] = sameTrkIt->momentum(0).z();
4492 m_mcEvtTrk_p[i] = sameTrkIt->momentum(0).mag();
4493 m_mcEvtTrk_phi[i] = sameTrkIt->direction(0).phi();
4494 m_mcEvtTrk_theta[i] = sameTrkIt->direction(0).theta();
4495 m_mcEvtTrk_cosTheta[i] = cos(sameTrkIt->direction(0).theta());
4496 m_mcEvtTrk_vx[i] = sameTrkIt->x(0).x();
4497 m_mcEvtTrk_vy[i] = sameTrkIt->x(0).y();
4498 m_mcEvtTrk_vz[i] = sameTrkIt->x(0).z();
4499 m_mcEvtTrk_vr[i] = sameTrkIt->x(0).perp();
4500 //m_mcEvtTrk_chi2[i] = sameTrkIt->getChi2();
4501 //m_mcEvtTrk_fiTerm[i] = sameTrkIt->
4502 //m_mcEvtTrk_nhit[i] = (sameTrkIt->getHotList()).size();
4503 //m_mcEvtTrk_ncluster[i] = sameTrkIt->
4504 //m_mcEvtTrk_stat[i] = sameTrkIt->
4505 //m_mcEvtTrk_ndof[i] = sameTrkIt->
4506 //m_mcEvtTrk_nster[i] = sameTrkIt->
4507 //m_mcEvtTrk_nlayer[i] = sameTrkIt->
4508 //m_mcEvtTrk_firstLayer[i] = sameTrkIt->
4509 //m_mcEvtTrk_lastLayer[i] = sameTrkIt->
4510 //m_mcEvtTrk_nCgemXClusters[i] = sameTrkIt->
4511 //m_mcEvtTrk_nCgemVClusters[i] = sameTrkIt->
4512 }
4513 i++;
4514 }
4515 ntuple_event->write();
4516 return recMdcTrackCol->size();
4517}
4518
4520{
4521 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
4522 if(!recMdcTrackCol)return 0;
4523 for(RecMdcTrackCol::iterator iter = recMdcTrackCol->begin();iter!=recMdcTrackCol->end();iter++){
4524 double dr = (*iter)->helix(0) ;
4525 double phi0 = (*iter)->helix(1) ;
4526 double kappa = (*iter)->helix(2) ;
4527 double dz = (*iter)->helix(3) ;
4528 double tanl = (*iter)->helix(4) ;
4529 cout<<setw(12)<<"dr:" <<setw(15)<<dr
4530 <<setw(12)<<"phi0:" <<setw(15)<<phi0
4531 <<setw(12)<<"kappa:" <<setw(15)<<kappa
4532 <<setw(12)<<"dz:" <<setw(15)<<dz
4533 <<setw(12)<<"tanl:" <<setw(15)<<tanl
4534 <<endl;
4535
4536 ClusterRefVec clusterRefVec = (*iter)->getVecClusters();
4537 ClusterRefVec::iterator clusterIt = clusterRefVec.begin();
4538 for(clusterIt=clusterRefVec.begin();clusterIt!=clusterRefVec.end();clusterIt++){
4539 //cout<<(*clusterIt)->;
4540 }
4541
4542 HitRefVec hitRefVec = (*iter)->getVecHits();
4543 HitRefVec::iterator hotIt = hitRefVec.begin();
4544 //cout<<"("<<"layer"<<","<<"wire"<<") "
4545 cout<<"("<<"l "<<","<<" w "<<") "
4546 //<<"Stat "
4547 //<<"FlagLR "
4548 <<"S "
4549 <<"F "
4550 <<"DriftLeft "
4551 <<" DriftRight "
4552 <<"ErrDrift_L "
4553 <<"ErrDrift_R "
4554 <<"ChisqAdd "
4555 //<<" Tdc "
4556 //<<" Adc "
4557 <<" DriftT "
4558 <<" Doca "
4559 <<" Entra "
4560 <<" Zhit "
4561 <<" FltLen "
4562 <<endl;
4563 for(hotIt=hitRefVec.begin();hotIt!=hitRefVec.end();hotIt++){
4564 int layer = MdcID::layer((*hotIt)->getMdcId());
4565 int wire = MdcID::wire((*hotIt)->getMdcId());
4566 cout<<"("<<setw( 2)<<layer<<","<<setw( 3)<<wire<<") "
4567 <<setw( 3)<<(*hotIt)->getStat()
4568 <<setw( 3)<<(*hotIt)->getFlagLR()
4569 <<setw(12)<<(*hotIt)->getDriftDistLeft()
4570 <<setw(12)<<(*hotIt)->getDriftDistRight()
4571 <<setw(12)<<(*hotIt)->getErrDriftDistLeft()
4572 <<setw(12)<<(*hotIt)->getErrDriftDistRight()
4573 <<setw(12)<<(*hotIt)->getChisqAdd()
4574 //<<setw( 6)<<(*hotIt)->getTdc()
4575 //<<setw( 6)<<(*hotIt)->getAdc()
4576 <<setw(10)<<(*hotIt)->getDriftT()
4577 <<setw(12)<<(*hotIt)->getDoca()
4578 <<setw(12)<<(*hotIt)->getEntra()
4579 <<setw(10)<<(*hotIt)->getZhit()
4580 <<setw(8 )<<(*hotIt)->getFltLen()
4581 <<endl;
4582 }
4583 cout<<endl;
4584 }
4585 return recMdcTrackCol->size();
4586}
4587
4588//cout<<__FILE__<<" "<<__LINE__<<endl;
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
bool sortCluster(const RecCgemCluster *clusterA, const RecCgemCluster *clusterB)
Double_t x[10]
TGraph * gr
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
XmlRpcServer s
vector< HoughHit >::iterator HitVector_Iterator
Definition HoughHit.h:183
bool moreHot(HoughTrack trk1, HoughTrack trk2)
Definition Hough.cxx:1594
bool largerPt(HoughTrack trk1, HoughTrack trk2)
Definition Hough.cxx:451
bool sortCluster(const RecCgemCluster *clusterA, const RecCgemCluster *clusterB)
Definition Hough.cxx:1918
****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
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
Definition KarFin.h:27
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
Definition KarFin.h:34
std::vector< MdcDigi * > MdcDigiVec
ObjectVector< RecMdcHit > RecMdcHitCol
Definition RecMdcHit.h:99
SmartRefVector< RecCgemCluster > ClusterRefVec
Definition RecMdcTrack.h:28
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
Definition RecMdcTrack.h:26
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
#define M_PI
Definition TConstant.h:4
#define X1
#define X2
const RecCgemCluster * baseHit() const
static int strip(const Identifier &id)
Definition CgemID.cxx:83
static int sheet(const Identifier &id)
Definition CgemID.cxx:77
static bool is_xstrip(const Identifier &id)
Definition CgemID.cxx:64
static const double pi
Definition Constants.h:38
HepVector getHelix()
vector< RecMdcHit > makeRecMdcHitVec(int sel=1)
void setPxy(const double pxy)
Definition DstMdcTrack.h:86
void setTrackId(const int trackId)
Definition DstMdcTrack.h:84
void setPy(const double py)
Definition DstMdcTrack.h:88
void setZ(const double z)
Definition DstMdcTrack.h:95
void setX(const double x)
Definition DstMdcTrack.h:93
void setError(double err[15])
void setTheta(const double theta)
Definition DstMdcTrack.h:91
void setStat(const int stat)
Definition DstMdcTrack.h:97
void setP(const double p)
Definition DstMdcTrack.h:90
void setHelix(double helix[5])
void setPoca(double poca[3])
void setR(const double r)
Definition DstMdcTrack.h:96
void setCharge(const int charge)
Definition DstMdcTrack.h:85
void setY(const double y)
Definition DstMdcTrack.h:94
void setChi2(const double chi)
Definition DstMdcTrack.h:98
void setPhi(const double phi)
Definition DstMdcTrack.h:92
void setPz(const double pz)
Definition DstMdcTrack.h:89
void setPx(const double px)
Definition DstMdcTrack.h:87
TArrayI GetIdentifier() const
Definition CgemMcHit.h:122
Identifier identify() const
Definition MdcMcHit.cxx:24
const HepPoint3D & pivot(void) const
returns pivot position.
int printTdsTrack()
Definition Hough.cxx:4519
StatusCode execute()
Definition Hough.cxx:299
int storeFlag
Definition Hough.h:69
int Layer
Definition Hough.h:66
int activeUnusedCgemHitsOnly(vector< HoughHit * > &hitPntList)
Definition Hough.cxx:3228
int checkTrack(vector< HoughTrack > &trackVector)
Definition Hough.cxx:1700
int storeRecTracks(RecMdcTrackCol *trackList, RecMdcHitCol *hitList, vector< HoughTrack > &trackVector)
Definition Hough.cxx:1922
int makeHoughHitList()
Definition Hough.cxx:456
StatusCode finalize()
Definition Hough.cxx:444
void solveSharedHits(vector< HoughHit * > &hitList)
Definition Hough.cxx:3252
int printFlag
Definition Hough.h:71
int storeTrack(vector< HoughTrack > &trackVector, RecMdcTrackCol *&recMdcTrackCol, RecMdcHitCol *&recMdcHitCol)
Definition Hough.cxx:1881
int storeTracks(RecMdcTrackCol *trackList, RecMdcHitCol *hitList, vector< HoughTrack > &trackVector)
Definition Hough.cxx:2207
vector< HoughTrack >::iterator getHoughTrkIt(vector< HoughTrack > &houghTrkList, int trkId)
Definition Hough.cxx:3297
StatusCode bookTuple()
Definition Hough.cxx:3603
int getMcHitCol()
Definition Hough.cxx:523
int m_useCgemInGlobalFit
Definition Hough.h:67
StatusCode initialize()
Definition Hough.cxx:108
void clearTrack(vector< HoughTrack > &trackVector)
Definition Hough.cxx:3199
HoughFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition Hough.cxx:31
int getMcParticleCol()
Definition Hough.cxx:741
int checkHot(vector< HoughTrack > &trackVector)
Definition Hough.cxx:1655
void printHitList()
Definition Hough.cxx:2717
int fillHistogram(HoughHit *hit, TH2D *hitMap, int charge, int vote)
Definition Hough.cxx:956
int m_clearTrack
Definition Hough.h:68
StatusCode registerTrack(RecMdcTrackCol *&trackList_tds, RecMdcHitCol *&hitList_tds)
Definition Hough.cxx:1828
void clearMemory()
Definition Hough.cxx:3212
void setCgemCluster(const RecCgemCluster *cgemCluster)
Definition HoughHit.h:75
vector< S_Z > getSZ() const
Definition HoughHit.h:63
static void setMdcGeomSvc(MdcGeomSvc *mdcGeomSvc)
Definition HoughHit.h:99
const RecCgemCluster * getCgemCluster() const
Definition HoughHit.h:41
double getDriftDist() const
Definition HoughHit.h:54
void setMdcHit(MdcHit *mdcHit)
Definition HoughHit.h:135
void setDigi(const MdcDigi *mdcDigi)
Definition HoughHit.h:76
const MdcMcHit * getMdcMcHit() const
Definition HoughHit.h:44
HepPoint3D getHitPosition() const
Definition HoughHit.h:51
HitType getHitType() const
Definition HoughHit.h:40
const CgemMcHit * getCgemMcHit() const
Definition HoughHit.h:43
void setPairHit(HoughHit *pairHit)
Definition HoughHit.h:116
static void setMdcCalibFunSvc(MdcCalibFunSvc *mdcCalibFunSvc)
Definition HoughHit.h:100
int getFlag() const
Definition HoughHit.h:47
void print()
Definition HoughHit.cxx:327
double driftTime()
Definition HoughHit.cxx:296
static void setCgemCalibFunSvc(CgemCalibFunSvc *cgemCalibFunSvc)
Definition HoughHit.h:102
void setWire(int wire)
Definition HoughHit.h:80
int getLayer() const
Definition HoughHit.h:45
void setFlag(int flag)
Definition HoughHit.h:81
static void setCgemGeomSvc(CgemGeomSvc *cgemGeomSvc)
Definition HoughHit.h:101
static void setMdcDetector(const MdcDetector *mdcDetector)
Definition HoughHit.h:103
int getWire() const
Definition HoughHit.h:46
@ CGEMMCHIT
Definition HoughHit.h:27
@ CGEMHIT
Definition HoughHit.h:27
@ MDCMCHIT
Definition HoughHit.h:27
static int m_useCgemInGlobalFit
Definition HoughTrack.h:147
static int m_clearTrack
Definition HoughTrack.h:146
void addVecStereoHitPnt(HoughHit *aHitPnt)
Definition HoughTrack.h:136
int getTrkID() const
Definition HoughTrack.h:49
int judgeHalf(HoughHit *hit)
void setMcTrack(HoughTrack *mcTrack)
Definition HoughTrack.h:143
vector< HoughHit * > getHotList(int type=2)
static TGraph * m_cut[2][43]
Definition HoughTrack.h:18
void addHitPnt(HoughHit *aHitPnt)
Definition HoughTrack.h:84
value_type get_value() const
Definition Identifier.h:163
int wireAmbig() const
double dcaToWire() const
double drift() const
double entranceAngle() const
const MdcLayer * layer() const
const MdcDigi * digi() const
Definition MdcHit.h:55
unsigned layernumber() const
Definition MdcHit.h:61
unsigned wirenumber() const
Definition MdcHit.h:62
unsigned adcIndex() const
Definition MdcHit.h:64
double driftTime(double tof, double z) const
Definition MdcHit.cxx:142
unsigned tdcIndex() const
Definition MdcHit.h:63
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition MdcID.cxx:49
static int wire(const Identifier &id)
Definition MdcID.cxx:54
int view(void) const
Definition MdcLayer.h:28
const MdcHit * mdcHit() const
void setNoInner(bool noInnerFlag)
static void readMCppTable(std::string filenm)
Definition Pdt.cxx:291
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
virtual Identifier identify() const
Definition RawData.cxx:15
int getclusterid(void) const
int getlayerid(void) const
int getflag(void) const
int getclusterflagb(void) const
int getclusterflage(void) const
void setMdcId(Identifier mdcid)
Definition RecMdcHit.h:67
void setErrDriftDistRight(double erddr)
Definition RecMdcHit.h:63
void setFltLen(double fltLen)
Definition RecMdcHit.h:74
const double getChisqAdd(void) const
Definition RecMdcHit.h:46
void setErrDriftDistLeft(double erddl)
Definition RecMdcHit.h:62
void setDriftDistLeft(double ddl)
Definition RecMdcHit.h:60
const Identifier getMdcId(void) const
Definition RecMdcHit.h:49
void setDoca(double doca)
Definition RecMdcHit.h:71
void setStat(int stat)
Definition RecMdcHit.h:66
void setTdc(double tdc)
Definition RecMdcHit.h:68
void setAdc(double adc)
Definition RecMdcHit.h:69
void setFlagLR(int lr)
Definition RecMdcHit.h:65
void setChisqAdd(double pChisq)
Definition RecMdcHit.h:64
const double getFltLen(void) const
Definition RecMdcHit.h:56
void setZhit(double zhit)
Definition RecMdcHit.h:73
void setDriftT(double driftT)
Definition RecMdcHit.h:70
void setDriftDistRight(double ddr)
Definition RecMdcHit.h:61
void setTrkId(int trkid)
Definition RecMdcHit.h:59
void setId(int id)
Definition RecMdcHit.h:58
void setEntra(double entra)
Definition RecMdcHit.h:72
void setVecClusters(ClusterRefVec vecclusters)
void setPivot(const HepPoint3D &pivot)
Definition RecMdcTrack.h:79
void setVZ0(double z0)
Definition RecMdcTrack.h:76
void setVY0(double y0)
Definition RecMdcTrack.h:75
void setVecHits(HitRefVec vechits)
void setFiTerm(double fiterm)
Definition RecMdcTrack.h:77
void setVX0(double x0)
Definition RecMdcTrack.h:74
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual void print(std::ostream &ostr) const =0
virtual double pt(double fltL=0.) const =0
virtual double chisq() const =0
virtual int charge() const =0
virtual int nDof() const =0
virtual const TrkDifTraj & traj() const =0
virtual HepPoint3D position(double fltL) const =0
double phi0() const
double omega() const
double z0() const
const HepVector & params() const
double d0() const
double tanDip() const
const HepSymMatrix & covariance() const
virtual TrkExchangePar helix(double fltL) const =0
hot_iterator begin() const
Definition TrkHitList.h:45
unsigned nHit() const
Definition TrkHitList.h:44
hot_iterator end() const
Definition TrkHitList.h:46
double fltLen() const
Definition TrkHitOnTrk.h:91
double resid(bool exclude=false) const
double hitRms() const
Definition TrkHitOnTrk.h:89
const TrkRep * getParentRep() const
Definition TrkHitOnTrk.h:73
bool isActive() const
TrkErrCode getFitStuff(HepVector &derivs, double &deltaChi) const
virtual double arrivalTime(double fltL) const
Definition TrkRep.cxx:192