BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
MucRecRoadFinder Class Reference

#include <MucRecRoadFinder.h>

+ Inheritance diagram for MucRecRoadFinder:

Public Member Functions

 MucRecRoadFinder (const std::string &name, ISvcLocator *pSvcLocator)
 
 ~MucRecRoadFinder ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
void TrackFinding (RecMucTrack *aTrack)
 

Detailed Description

Reconstruction of Muon Chamber tracks by combining two 2DRoads to form a 3DRoad.

Author
Zhengyun You \URL{youzy.nosp@m.@hep.nosp@m..pku..nosp@m.cn}

Definition at line 28 of file MucRecRoadFinder.h.

Constructor & Destructor Documentation

◆ MucRecRoadFinder()

MucRecRoadFinder::MucRecRoadFinder ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 48 of file MucRecRoadFinder.cxx.

48 :
49 Algorithm(name, pSvcLocator)
50{
51 // Declare the properties
52 declareProperty("FittingMethod", m_fittingMethod = 2);
53 declareProperty("ConfigFile", m_configFile = "MucConfig.xml");
54 declareProperty("McCosmic", m_mccosmic = 0);
55 declareProperty("OnlySeedFit", m_onlyseedfit = 0);
56 declareProperty("NtOutput", m_NtOutput = 0);
57 declareProperty("MaxHitsRec", m_maxHitsRec = 200);
58 declareProperty("United", m_united = 0);
59 declareProperty("SeedType", m_seedtype = 0);
60 declareProperty("MsOutput", m_MsOutput = false);
61}

◆ ~MucRecRoadFinder()

MucRecRoadFinder::~MucRecRoadFinder ( )
inline

Definition at line 32 of file MucRecRoadFinder.h.

32{};

Member Function Documentation

◆ execute()

StatusCode MucRecRoadFinder::execute ( )

Definition at line 146 of file MucRecRoadFinder.cxx.

146 {
147
148 MsgStream log(msgSvc(), name());
149 log << MSG::INFO << "in execute()" << endreq;
150
151 // Part 1: Get the event header, print out event and run number
152 int event, run;
153
154 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
155 if (!eventHeader) {
156 log << MSG::FATAL << "Could not find Event Header" << endreq;
157 return( StatusCode::FAILURE);
158 }
159 log << MSG::INFO << "Run: " << eventHeader->runNumber() << " Event: " << eventHeader->eventNumber() << endreq;
160
161 int digiId;
162
163 //Part 2: Retrieve MC truth
164
165 Hep3Vector cosmicMom;
166 if(m_mccosmic==1){
167 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
168 if (!mcParticleCol) {
169 log << MSG::FATAL << "Could not find McParticle" << endreq;
170 return( StatusCode::FAILURE);
171 }
172
173 McParticleCol::iterator iter_mc = mcParticleCol->begin();
174 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
175 log << MSG::DEBUG
176 << " particleId = " << (*iter_mc)->particleProperty()
177 << endreq;
178 int pid = (*iter_mc)->particleProperty();
179 //cout<<"in mucroadfinder pid = "<<pid<<endl;
180 if(fabs(pid)!=13) continue;
181
182 HepLorentzVector initialMomentum = (*iter_mc)->initialFourMomentum();
183 Hep3Vector startP(initialMomentum.px(), initialMomentum.py(), initialMomentum.pz());
184 Hep3Vector rotate(-initialMomentum.px(),initialMomentum.pz(),initialMomentum.py());
185
186 if(m_NtOutput>=1){
187 m_px_mc = initialMomentum.px();
188 m_py_mc = initialMomentum.py();
189 m_pz_mc = initialMomentum.pz();
190
191 m_theta_mc = rotate.theta();
192 m_phi_mc = rotate.phi();
193
194 m_theta_mc_pipe = startP.theta();
195 m_phi_mc_pipe = startP.phi();
196
197 //m_tuple->write();
198 }
199
200 //if(initialMomentum.py()>0)cout<<"py>0????? "<<pid<<endl;
201 cosmicMom = startP;
202
203 }
204 }
205 /*
206 //Part 3: Retrieve MDC digi
207 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
208 if (!mdcDigiCol) {
209 log << MSG::FATAL << "Could not find MDC digi" << endreq;
210 return( StatusCode::FAILURE);
211 }
212
213 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
214 digiId = 0;
215
216 for (;iter1 != mdcDigiCol->end(); iter1++, digiId++) {
217 log << MSG::INFO << "MDC digit No: " << digiId << endreq;
218
219 log << MSG::INFO
220 << " time_channel = " << (*iter1)->getTimeChannel()
221 << " charge_channel = " << (*iter1)->getChargeChannel()
222 << endreq;
223 }
224
225 //Part 4: Retrieve TOF digi
226 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc(),"/Event/Digi/TofDigiCol");
227 if (!tofDigiCol) {
228 log << MSG::FATAL << "Could not find TOF digi" << endreq;
229 return( StatusCode::FAILURE);
230 }
231
232 TofDigiCol::iterator iter2 = tofDigiCol->begin();
233 digiId = 0;
234
235 for (;iter2 != tofDigiCol->end(); iter2++, digiId++) {
236 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
237
238 }
239
240 //Part 5: Retrieve EMC digi
241 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),"/Event/Digi/EmcDigiCol");
242 if (!emcDigiCol) {
243 log << MSG::FATAL << "Could not find EMC digi" << endreq;
244 return( StatusCode::FAILURE);
245 }
246
247 EmcDigiCol::iterator iter3 = emcDigiCol->begin();
248 digiId = 0;
249
250 for (;iter3 != emcDigiCol->end(); iter3++, digiId++) {
251 log << MSG::INFO << "Emc digit No: " << digiId << endreq;
252
253 log << MSG::INFO
254 << " time_channel = " << (*iter3)->getTimeChannel()
255 << " charge_channel = " << (*iter3)->getChargeChannel()
256 << endreq;
257 }
258 */
259
260 //Part 6: Retrieve MUC digi
261 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),"/Event/Digi/MucDigiCol");
262 if (!mucDigiCol) {
263 log << MSG::FATAL << "Could not find MUC digi" << endreq;
264 return( StatusCode::FAILURE);
265 }
266
267 MucDigiCol::iterator iter4 = mucDigiCol->begin();
268 digiId = 0;
269 for (;iter4 != mucDigiCol->end(); iter4++, digiId++) {
270 }
271 log << MSG::INFO << "MUC digis:: " << digiId << endreq;
272 if( digiId == 0) return( StatusCode::SUCCESS );
273
274 //********************************//
275 RecMucTrackCol *aMucTrackCol;
276 int trackId = -1;
277 int muctrackId = -1;
278
279 if(m_united != 1) // if this algorithm run individualy, we need create hitcollection and trackcollection...
280 {
281 Identifier mucID;
282 if (!aMucRecHitContainer) {
283 aMucRecHitContainer = new MucRecHitContainer();
284 }
285 aMucRecHitContainer->Clear();
286
287 MucRecHitCol *aMucRecHitCol = new MucRecHitCol();
288 aMucRecHitContainer->SetMucRecHitCol(aMucRecHitCol);
289
290
291 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
292 DataObject *mucRecHitCol;
293 eventSvc()->findObject("/Event/Recon/MucRecHitCol",mucRecHitCol);
294 if(mucRecHitCol != NULL) {
295 dataManSvc->clearSubTree("/Event/Recon/MucRecHitCol");
296 eventSvc()->unregisterObject("/Event/Recon/MucRecHitCol");
297 }
298
299 StatusCode sc = eventSvc()->registerObject("/Event/Recon/MucRecHitCol", aMucRecHitContainer->GetMucRecHitCol());
300
301 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
302 int mucDigiId = 0;
303 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
304 mucID = (*iterMuc)->identify();
305 int part = MucID::barrel_ec(mucID);
306 int seg = MucID::segment(mucID);
307 int gap = MucID::layer(mucID);
308 int strip = MucID::channel(mucID);
309 //aMucRecHitContainer->AddHit(mucID);
310 //if(part==1 && seg==2 && gap==8 && (strip==19||strip==16));//cout<<"noise hit!!!=========="<<endl;
311 //else /////this problem has been solved!
312 aMucRecHitContainer->AddHit(part, seg, gap, strip);
313 log << MSG::INFO << " digit" << mucDigiId << " : "
314 << " part " << part
315 << " seg " << seg
316 << " gap " << gap
317 << " strip " << strip
318 << endreq;
319 }
320
321 DataObject *aReconEvent ;
322 eventSvc()->findObject("/Event/Recon",aReconEvent);
323 if(aReconEvent==NULL) {
324 //then register Recon
325 aReconEvent = new ReconEvent();
326 StatusCode sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
327 if(sc!=StatusCode::SUCCESS) {
328 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
329 return( StatusCode::FAILURE);
330 }
331 }
332 StatusCode fr = eventSvc()->findObject("/Event/Recon",aReconEvent);
333 if(fr!=StatusCode::SUCCESS) {
334 log << MSG::WARNING << "Could not find register ReconEvent, will create it" <<endreq;
335 StatusCode sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
336 if(sc!=StatusCode::SUCCESS) {
337 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
338 return( StatusCode::FAILURE);
339 }
340 }
341
342 //********************************//
343 // Create track Container;
344 DataObject *mucTrackCol;
345 eventSvc()->findObject("/Event/Recon/RecMucTrackCol",mucTrackCol);
346 if(mucTrackCol != NULL) {
347 dataManSvc->clearSubTree("/Event/Recon/RecMucTrackCol");
348 eventSvc()->unregisterObject("/Event/Recon/RecMucTrackCol");
349 }
350
351 aMucTrackCol = new RecMucTrackCol();
352 sc = eventSvc()->registerObject("/Event/Recon/RecMucTrackCol", aMucTrackCol);
353 aMucTrackCol->clear();
354
355 // check MucTrackCol registered
356 SmartDataPtr<RecMucTrackCol> findMucTrackCol(eventSvc(),"/Event/Recon/RecMucTrackCol");
357 if (!findMucTrackCol) {
358 log << MSG::FATAL << "Could not find RecMucTrackCol" << endreq;
359 return( StatusCode::FAILURE);
360 }
361 aMucTrackCol->clear();
362
363
364 log << MSG::INFO <<"MaxHitsRec : "<<m_maxHitsRec<< endreq;
365 if(digiId> m_maxHitsRec) return StatusCode::SUCCESS; //too many digit! abnormal------2008-04-17
366 //********************************//
367 // Create track Container;
368
369 trackId = 0;
370 muctrackId = 0;
371 }//// conrespond to if(m_united != 1) !!!!!!!
372 else if(m_united == 1){
373
374 Identifier mucID;
375 if (!aMucRecHitContainer) {
376 aMucRecHitContainer = new MucRecHitContainer();
377 }
378 aMucRecHitContainer->Clear();
379
380 SmartDataPtr<MucRecHitCol> aMucRecHitCol (eventSvc(),"/Event/Recon/MucRecHitCol");
381 if(aMucRecHitCol == NULL) {
382 log << MSG::WARNING << "MucRecHitCol is NULL" << endreq;
383 }
384
385 aMucRecHitContainer->SetMucRecHitCol(aMucRecHitCol);
386
387 SmartDataPtr<RecMucTrackCol> mucTrackCol (eventSvc(),"/Event/Recon/RecMucTrackCol");
388 if(mucTrackCol == NULL) {
389 log << MSG::WARNING << "aMucTrackCol is NULL" << endreq;
390 }
391
392 log << MSG::INFO <<"mucTrackCol size: "<<mucTrackCol->size()<<" hitCol size: "<<aMucRecHitCol->size()<<endreq;
393 aMucTrackCol = mucTrackCol;
394
395 // Retrieve Ext track Col from TDS for setting trackId
396 SmartDataPtr<RecExtTrackCol> aExtTrackCol(eventSvc(),"/Event/Recon/RecExtTrackCol");
397 if (!aExtTrackCol) {
398 log << MSG::WARNING << "Can't find ExtTrackCol in TDS!" << endreq;
399 }
400
401 SmartDataPtr<RecMdcTrackCol> aMdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
402 if (!aMdcTrackCol) {
403 log << MSG::WARNING << "Can't find MdcTrackCol in TDS!" << endreq;
404 }
405
406 if( aExtTrackCol && aMdcTrackCol ) trackId = aMdcTrackCol->size();
407 muctrackId = aMucTrackCol->size();
408 }
409
410 int hasEmcUp = 0;
411 int hasEmcDown = 0;
412 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
413 if (!aShowerCol) {
414 log << MSG::WARNING << "Could not find RecEmcShowerCol" << endreq;
415 //return( StatusCode::FAILURE);
416 }
417 else{
418 RecEmcShowerCol::iterator iShowerCol;
419 for(iShowerCol=aShowerCol->begin();
420 iShowerCol!=aShowerCol->end();
421 iShowerCol++){
422 /*
423 cout<<"check EmcRecShowerCol registered:"<<endl;
424 cout<<"shower id: "<<(*iShowerCol)->ShowerId()<<"\t"
425 <<"shower energy: "<<(*iShowerCol)->Energy()<<"\n"
426 <<"shower position: "<<(*iShowerCol)->Position()<<endl;
427 */
428 if(((*iShowerCol)->position()).phi()>0&&((*iShowerCol)->position()).phi()<3.1415926) hasEmcUp++;
429 else hasEmcDown++;
430 }
431 }
432 if(m_NtOutput >= 1){
433 m_emcUp = hasEmcUp; m_emcDown = hasEmcDown;
434 }
435
436 //********************************//
437 m_NEvent++;
439 // Find or create the 3D road container ...
440 if (!p3DRoadC) {
441 p3DRoadC = new MucRec3DRoadContainer();
442 }
443 p3DRoadC->clear(); // make sure that the container is empty
444
446 // Find or create the 2D road0 container ...
447 if (!p2DRoad0C) {
448 p2DRoad0C = new MucRec2DRoadContainer();
449 }
450 p2DRoad0C->clear(); // make sure that the container is empty
451
453 // Find or create the 2D road1 container ...
454 if (!p2DRoad1C) {
455 p2DRoad1C = new MucRec2DRoadContainer();
456 }
457 p2DRoad1C->clear(); // make sure that the container is empty
458 log << MSG::INFO << "Muc 2D 3D Road Container created" << endreq;
459
460 // We have all of the input and output parameters now, so do
461 // something useful with them!
462 //static bool first_call = true;
463 //
464 // Now find some roads!
465 //
466
467 MucRecHit *pHit0 = 0, *pHit1 = 0;
468 int count0, count1, count, iGap0, iGap1;
469 int orient;
470
471 for (int iPart = 0; iPart < (int)MucID::getPartNum(); iPart++) {
472 for (int iSeg = 0; iSeg < (int)MucID::getSegNum(iPart); iSeg++) {
473 for (int iOrient = 0; iOrient < 2; iOrient++) {
474 int nLoops = 1;
475 if(m_seedtype == 1) nLoops = kNSeedLoops;
476 for (int iLoop = 0; iLoop < nLoops; iLoop++) { //now only 1 loop
477 // checkout the seed gap(s) from search order
478 int length = kSearchLength[iLoop][iPart][iOrient];
479 if(m_seedtype == 1){
480 iGap0 = kSearchOrder[iLoop][iPart][iOrient][0];
481 iGap1 = kSearchOrder[iLoop][iPart][iOrient][1];
482 }
483 else { //new method to calc seed gaps------//
484 int setgap0 = 0;
485 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
486 int mucDigiId = 0;
487 Identifier mucID;
488 iGap0 = 0; iGap1 = 0;
489 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
490 mucID = (*iterMuc)->identify();
491 int part = MucID::barrel_ec(mucID);
492 int seg = MucID::segment(mucID);
493 int gap = MucID::layer(mucID);
494 int strip = MucID::channel(mucID);
495 int orient = 0;
496 if ( (part == 1 && gap % 2 == 0) || (part != 1 && gap % 2 == 1) ) orient = 1;
497
498 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 0){
499 iGap0 = gap;
500 setgap0 = 1;
501 }//make sure that iGap0 record the 1st gap in this orient
502 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 1 && gap != iGap0 ){
503 iGap1 = gap;
504 }//make sure that iGap1 record the last gap in this orient
505 }
506 }
507 //
508 if(m_MsOutput) cout <<"Find seed gap in ( "<<iPart<<" "<<iSeg<<" ) gap0: "<<iGap0<<" gap1: "<<iGap1<<endl;
509
510 //new method to calc seed gaps------//
511 if(iGap0 > iGap1){
512 int tempGap = iGap0;
513 iGap0 = iGap1;
514 iGap1 = tempGap;
515 }
516 if(iGap1 == iGap0) continue;
517
518 count0 = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap0);
519 for (int iHit0 = 0; iHit0 < count0; iHit0++) {
520 //cout << "iHit0 = " << iHit0 << endl;
521 pHit0 = aMucRecHitContainer->GetHit(iPart, iSeg, iGap0, iHit0);
522 if (!pHit0) {
523 log << MSG::FATAL << "MucRecRoadFinder-E10 " << " part " << iPart
524 << " seg " << iSeg << " gap " << iGap0 << " null pointer"
525 << endl;
526 }
527 else {
528
529 //this algo use with ext and this hit has been used before;
530 if(m_united == 1 && pHit0->GetHitMode() != -1) continue;
531
532 count1 = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap1);
533 if(m_MsOutput) cout << "part " << iPart << " seg " << iSeg << " orient " << iOrient
534 << " gap0 " << iGap0 << " count0 " << count0
535 << " gap1 " << iGap1 << " count1 " << count1 << endl;
536 for (int iHit1 = 0; iHit1 < count1; iHit1++) {
537 //cout << "iHit1 = " << iHit1 << endl;
538 pHit1 = aMucRecHitContainer->GetHit(iPart, iSeg, iGap1, iHit1);
539 if (!pHit1) {
540 log << MSG::ERROR << "MucRecRoadFinder-E10 " << " part " << iPart
541 << " seg " << iSeg << " gap " << iGap1 << " null pointer"
542 << endl;
543 } else {
544
545 //this algo use with ext and this hit has been used before;
546 if(m_united == 1 && pHit1->GetHitMode() != -1) continue;
547
548 // Found seed hit(s), create a new 2D road object,
549 // and attach hit pHit1 and pHit0
550 MucRec2DRoad *road2D = new MucRec2DRoad(iPart, iSeg, iOrient, 0.0, 0.0, 3000.0);
551 if (!road2D) {
552 log << MSG::FATAL << "MucRecRoadFinder-E20 " << "failed to create 2D road!" << endreq;
553 continue;
554 }
556
557 if (!pHit0->GetGap()) log << MSG::ERROR << "pHit0->GetGap(), null pointer" << endreq;
558 if (pHit0->GetGap()->Orient() == iOrient) {
559 //float xStrip, yStrip, zStrip;
560 //MucRecGeometry::GetPointer()->GetStripPointer(pHit0->GetSoftID())->GetCenterPos(xStrip, yStrip, zStrip);
561 //cout << " x = " << xStrip << " y = " << yStrip << " z = " << zStrip << endl;
562
563 //set hit as seed then
564 bool isseed = true;
565 pHit0->SetHitSeed(true);
566 pHit1->SetHitSeed(true);
567
568 road2D->AttachHit(pHit0);
569 if(m_MsOutput) cout << "pHit0 attached, " << road2D->GetTotalHits()
570 << ", hitId= "<<pHit0->Part()<<" "<<pHit0->Seg()<<" "<<pHit0->Gap()<<" "<<pHit0->Strip()<<endl;
571 }
572
573 if (pHit1->GetGap()->Orient() == iOrient) {
574 //cout << pHit1->GetSoftID() << endl;
575 //float xStrip, yStrip, zStrip;
576 //MucRecGeometry::GetPointer()->GetStripPointer(pHit1->GetSoftID())->GetCenterPos(xStrip, yStrip, zStrip);
577 //cout << " x = " << xStrip << " y = " << yStrip << " z = " << zStrip << endl;
578 road2D->AttachHit(pHit1);
579 if(m_MsOutput) cout << "pHit1 attached, " << road2D->GetTotalHits()
580 << ", hitId= "<<pHit1->Part()<<" "<<pHit1->Seg()<<" "<<pHit1->Gap()<<" "<<pHit1->Strip()<<endl;
581 }
582 if(m_MsOutput) cout << "Hit cout " << road2D->GetTotalHits() << ", slope " << road2D->GetSlope() << endl;
583
584 // After first (two) hit(s) is(are) attached,
585 // calculate reference pos, direction.
586 // Project to the other planes;
587 // attach clusters within search window.
588
589 for (int i = 0; i < length; i++) {
590 int iGap = kSearchOrder[iLoop][iPart][iOrient][i];
591
592 float dXmin = kInfinity;
593 MucRecHit *pHit = 0;
594
595 float Win = kWindowSize[iPart][iGap];
596 //Win = road2D->GetSearchWindowSize(iGap);
597
598 // following line should be removed after
599 // we have a good function classes for search window
600 //Win = WindowParGamma[iGap];
601
602 //search hit in iGap
603 count = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap);
604 for (int iHit = 0; iHit < count; iHit++) {
605 pHit = aMucRecHitContainer->GetHit(iPart, iSeg, iGap, iHit);
606 if (!pHit) {
607 log << MSG::FATAL << "MucRecRoadFinder-E20 null cluster pointer pHit" << endreq;
608 continue;
609 }
610 else {
611
612 //this algo use with ext and this hit has been used before;
613 if(m_united == 1 && pHit->GetHitMode() != -1) continue;
614
615 // Get the displacement of hit pHit to road2D
616 float dX = road2D->GetHitDistance(pHit);
617 if(m_MsOutput) cout<<"dX = "<<dX<<" Win = "<<Win<<", hit: "<<pHit->Part()<<" "<<pHit->Seg()<<" "<<pHit->Gap()<<" "<<pHit->Strip()<<endl;
618
619 if (dX < Win) {
620 // Attach the hit if it exists
621 // cout << "meet window " << pHit->GetSoftID() << endl;
622 if(iGap == iGap0 || iGap == iGap1) { //hits in these gap is used to be seed, so unvailable for calibrate effi;
623 if(pHit->GetHitMode() == -1){
624 pHit->SetHitMode(3); //self road finder mode
625 }
626 else if(pHit->GetHitMode() == 3){
627 pHit->SetHitMode(4); //self road finder mode used!!!
628 }
629 }
630 // attach hits if we need fit or hit. OR, only attach hits not in seed layers
631 if(m_onlyseedfit == 0)road2D->AttachHit(pHit);
632 else {
633 if(iGap == iGap0 || iGap == iGap1) road2D->AttachHit(pHit);
634 else road2D->AttachHitNoFit(pHit);
635 }
636 }
637 }
638 }
639
640
641 } // for (int i = 0; i < length; ...), Search all gaps
642
643
644 // Ok we found a road already, we need to know
645 // whether we should save it or not
646 // check road quality...
647 //
648
649 // 1. last gap of the road
650 bool lastGapOK = false;
651 if ( road2D->GetLastGap() >= kMinLastGap2D ) {
652 lastGapOK = true;
653 }
654 else {
655 log<<MSG::INFO << " 2D lastGap " << road2D->GetLastGap() << " < " << kMinLastGap2D << endreq;
656 }
657
658 // 2. positon at reference plane
659
660 // 3. number of gaps contain hits
661 bool firedGapsOK = false;
662 if (road2D->GetNGapsWithHits() >= kMinFiredGaps) {
663 firedGapsOK = true;
664 }
665 else {
666 log<<MSG::INFO << " 2D firedGaps " << road2D->GetNGapsWithHits() << " < " << kMinFiredGaps << endreq;
667 }
668
669 // 4. duplicated road check
670 bool duplicateRoad = false;
671 int maxSharedHits = 0, sharedHits = 0;
672 if (iOrient == 0) {
673 for (int index = 0; index < (int)p2DRoad0C->size(); index++) {
674 sharedHits =(*p2DRoad0C)[index]->GetNSharedHits(road2D);
675 }
676 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
677 }
678 else {
679 for (int index = 0; index < (int)p2DRoad1C->size(); index++) {
680 sharedHits = (*p2DRoad1C)[index]->GetNSharedHits(road2D);
681 }
682 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
683 }
684
685 if(road2D->GetTotalHits() == maxSharedHits
686 || maxSharedHits >= kMinSharedHits2D ) {
687 duplicateRoad = true;
688 log<<MSG::INFO << " maxSharedHits " << maxSharedHits << " > " << kMinSharedHits2D << endreq;
689 }
690
691 // Here is our criteria for a candidate road
692 // i.e. 1) There are at least two gaps containing hits
693 // 2) LastGap of the road passes last plane cut
694 // 3) Reference position passes vertex cut
695 // 4) No existing road share same hits with the road
696
697 if (lastGapOK && firedGapsOK && !duplicateRoad) {
698 if (iOrient == 0) {
699 log<<MSG::INFO << "Add a road0" << endreq;
700 p2DRoad0C->add(road2D);
701 }
702 else {
703 log<<MSG::INFO << "Add a road1" << endreq;
704 p2DRoad1C->add(road2D);
705 }
706 }
707 else {
708
709 // reset hit mode to be -1 if this road useless!
710 vector<MucRecHit*> road2DHits = road2D->GetHits();
711 for(int i=0; i< road2DHits.size(); i++)
712 {
713 MucRecHit *ihit = road2DHits[i];
714 if(ihit->Gap() == iGap0 || ihit->Gap() == iGap1){
715 if(ihit->GetHitMode() == 3) ihit->SetHitMode(-1);
716 if(ihit->GetHitMode() == 4) ihit->SetHitMode(3);
717 }
718 }
719 delete road2D;
720 }
721 } // else {
722 } // for ( int iHit = 0 ...)
723 } // else {
724 } // for ( int iHit0 ...)
725 } // for (int iLoop ...)
726 } // for (int iOrient ...)
727 } // for (int iSeg ...)
728 } // for(iPartArm ...)
729
730 int print2DRoadInfo = 0;
731 if (print2DRoadInfo == 1) {
732 // print 2DRoad container info.
733 cout << "In 2DRoad container : " << endl
734 << " Num of 2DRoad0 = " << p2DRoad0C->size() << endl
735 << endl;
736
737 for (int iRoad = 0; iRoad < (int)p2DRoad0C->size(); iRoad++) {
738
739 MucRec2DRoad *road = (*p2DRoad0C)[iRoad];
740 cout << " " << iRoad << "th 2DRoad0 :" << endl
741 << " Part = " << road->GetPart() << endl
742 << " Seg = " << road->GetSeg() << endl
743 << " Orient = " << road->GetOrient() << endl
744 << " LastGap = " << road->GetLastGap() << endl
745 << " TotalHits = " << road->GetTotalHits() << endl
746 << " DOF = " << road->GetDegreesOfFreedom() << endl
747 << " Slope = " << road->GetSlope() << endl
748 << " Intercept = " << road->GetIntercept() << endl
749 << endl;
750 //road->PrintHitsInfo();
751 }
752
753 cout << " Num of 2DRoad1 = " << p2DRoad1C->size() << endl
754 << endl;
755
756 for ( int iRoad = 0; iRoad < (int)p2DRoad1C->size(); iRoad++) {
757
758 MucRec2DRoad *road = (*p2DRoad1C)[iRoad];
759 cout << " " << iRoad << "th 2DRoad1 :" << endl
760 << " Part = " << road->GetPart() << endl
761 << " Seg = " << road->GetSeg() << endl
762 << " Orient = " << road->GetOrient() << endl
763 << " LastGap = " << road->GetLastGap() << endl
764 << " TotalHits = " << road->GetTotalHits() << endl
765 << " DOF = " << road->GetDegreesOfFreedom() << endl
766 << " Slope = " << road->GetSlope() << endl
767 << " Intercept = " << road->GetIntercept() << endl
768 << endl;
769 //road->PrintHitsInfo();
770 }
771 }
772
773 // We found all possible 2D roads in one part and seg
774 // and now it is time to construct 3D roads base on those 2D roads
775 for ( int iRoad0 = 0; iRoad0 < (int)p2DRoad0C->size(); iRoad0++) {
776 MucRec2DRoad *road0 = (*p2DRoad0C)[iRoad0];
777 for ( int iRoad1 = 0; iRoad1 < (int)p2DRoad1C->size(); iRoad1++){
778 MucRec2DRoad *road1 = (*p2DRoad1C)[iRoad1];
779
780 // Create a new road object with road0 and road1
781 if ( !(road0 &&road1) ) {
782 cout << "Null pointer to road0 or road1: "
783 << "road0 = " << road0
784 << "road1 = " << road1
785 << endl;
786 continue;
787 }
788
789 // Check that both 1D roads are in the same part and segment.
790 if ( (road0->GetPart() != road1->GetPart())
791 || (road0->GetSeg() != road1->GetSeg()) ) {
792 continue;
793 }
794
795 MucRec3DRoad *road3D = new MucRec3DRoad(road0, road1);
796
797 // What are our criteria for accepting a road as valid?
798 // Check them here.
799 // 1. difference of total number clusters in road0 and in road1
800 // 2. difference of last gaps in road0 and road1
801 // 3. InterSection OK or not (if X Y clusters in each gap are
802 // in same panel or overlap region)
803 // 4. Reference position check
804 // 5. Chisquare check
805 // 6. Last Gap check
806 // 7. Duplicate road check
807
808 bool lastGapDeltaOK = false;
809 if ( road3D->GetLastGapDelta() <= kMaxDeltaLastGap ) {
810 lastGapDeltaOK = true;
811 }
812 else {
813 cout << "LastGapDelta = " << road3D->GetLastGapDelta() << endl;
814 }
815
816 bool totalHitsDeltaOK = false;
817 if ( road3D->GetTotalHitsDelta() <= kMaxDeltaTotalHits ) {
818 totalHitsDeltaOK = true;
819 }
820 else {
821 //cout << "TotalHitsDelta = " << road3D->GetTotalHitsDelta() << endl;
822 }
823
824 bool chiSquareCutOK = false;
825 float xChiSquare = road0->GetReducedChiSquare();
826 float yChiSquare = road1->GetReducedChiSquare();
827 if ( xChiSquare <= kMaxXChisq
828 && yChiSquare <= kMaxYChisq ) {
829 chiSquareCutOK = true;
830 }
831 else {
832 cout << "xChiSquare = " << xChiSquare
833 << "yChiSquare = " << yChiSquare
834 << endl;
835 }
836
837 bool minLastGapOK = false;
838 if ( road3D->GetLastGap() >= kMinLastGap3D ) {
839 minLastGapOK = true;
840 }
841 else {
842 log<<MSG::INFO << " minLastGap = " << road3D->GetLastGap() << endreq;
843 }
844
845 bool duplicateRoad = false;
846 int maxSharedHits = 0, sharedHits = 0;
847 for ( int i = 0; i < (int)p3DRoadC->size(); i++){
848 sharedHits =(*p3DRoadC)[i]->GetNSharedHits(road3D);
849 if ( maxSharedHits < sharedHits) maxSharedHits = sharedHits;
850
851 //cout<<"judge shared hits: road["<<i<<"] max = "<<maxSharedHits<<endl;
852 }
853 if(road3D->GetTotalHits() == maxSharedHits
854 || maxSharedHits >= kMinSharedHits2D ) {
855 duplicateRoad = true;
856 log<<MSG::INFO << " MaxShareHits = " << maxSharedHits << endreq;
857 }
858
859 if ( lastGapDeltaOK &&
860 totalHitsDeltaOK &&
861 chiSquareCutOK &&
862 minLastGapOK &&
863 !duplicateRoad ) {
864 float vx, vy, x0, y0;
865 float slope1 = 100, slope0 = 100;
866 if(fabs(road1->GetSlope())<100) slope1 = road1->GetSlope();
867 if(fabs(road0->GetSlope())<100) slope0 = road0->GetSlope();
868
869 if ( road3D->GetPart() == 1 ){
870 road3D->TransformPhiRToXY( slope1, slope0,
871 road1->GetIntercept(), road0->GetIntercept(),
872 vx, vy, x0, y0);
873 }
874 else {
875 vx = slope1;
876 x0 = road1->GetIntercept();
877 vy = slope0;
878 y0 = road0->GetIntercept();
879 }
880 road3D->SetSimpleFitParams(vx, x0, vy, y0);
881
882 log<<MSG::INFO << "Add a 3D Road ... " << endreq;
883
884 float startx = 0.0, starty = 0.0, startz = 0.0;
885 float sigmax = 0.0, sigmay = 0.0, sigmaz = 0.0;
886 road3D->ProjectWithSigma(0, startx, starty, startz, sigmax, sigmay, sigmaz);//gap0
887
888 //cout<<"slope1,0 = "<<slope1<<" "<<slope0<<" vx,y = "<<vx<<" "<<vy<<endl;
889 //cout<<"startxyz= "<<startx<<" "<<starty<<" "<<startz<<endl;
890 //mom(vx,vy,1)
891 float vz = 1;
892 float sign = vy/fabs(vy);
893 float signx = vx/fabs(vx);
894 //cout<<"vxyz = "<<vx<<" "<<vy<<" "<<vz<<endl;
895 if(road3D->GetPart() == 1){
896 if(road3D->GetSeg() > 4){ //down segment
897
898 vx *= -sign;
899 vy *= -sign;
900 vz *= -sign;
901 }
902 else if(road3D->GetSeg()<2){
903 vx *= signx;
904 vy *= signx;
905 vz *= signx;
906 }
907 else if(road3D->GetSeg()>=3 && road3D->GetSeg()<=4){
908 vx *= -signx;
909 vy *= -signx;
910 vz *= -signx;
911 }
912 else{
913 vx *= sign;
914 vy *= sign;
915 vz *= sign;
916 }
917 }
918 else if(road3D->GetPart() == 0){
919 //fix me
920
921 //cout<<"startxyz= "<<startx<<" "<<starty<<" "<<startz<<endl;
922 //cout<<"vx,y,z = "<<vx<<" "<<vy<<" "<<vz<<endl;
923 //cout<<"in road finder a endcap finded!!! -------------"<<endl;
924 }
925 else if(road3D->GetPart() == 2){
926 //fix me
927
928 vx *= -1;
929 vy *= -1;
930 vz *= -1;
931 //cout<<"startxyz= "<<startx<<" "<<starty<<" "<<startz<<endl;
932 //cout<<"vx,y,z = "<<vx<<" "<<vy<<" "<<vz<<endl;
933 //cout<<"in road finder a endcap finded!!! ------------2-"<<endl;
934
935 }
936
937
938 Hep3Vector mom(vx, vy, vz);
939
940 ////////////construct track
941 //MucTrack *aTrack = new MucTrack(road3D);
942 //cout<<"startxyz = "<<startx<<" "<<starty<<" "<<startz<<endl;
943 //cout<<"vxyz = "<<vx<<" "<<vy<<" "<<vz<<endl;
944
945 startx /= 10; starty /= 10; startz /= 10; //mm->cm
946 startx -= vx/mom.mag(); starty -= vy/mom.mag(); startz -= vz/mom.mag(); // decrease a little
947
948 //cout<<"startxyz = "<<startx<<" "<<starty<<" "<<startz<<endl;
949 RecMucTrack *aTrack = new RecMucTrack();
950 aTrack->SetExtMucPos(startx, starty, startz); //mm->cm
951 aTrack->SetExtMucMomentum(vx, vy, vz);
952 aTrack->SetMucPos(startx, starty, startz);
953 aTrack->SetMucMomentum(vx, vy, vz);
954 aTrack->SetCurrentPos( startx, starty, startz);
955 aTrack->SetCurrentDir( vx, vy, vz);
956 aTrack->SetRecMode(3);
957 //aTrack->LineFit(1);
958 //aTrack->ComputeTrackInfo(1);
959
960 aTrack->setTrackId(trackId);
961 aTrack->setId(muctrackId);
962 trackId++;
963 muctrackId++;
964
965 //cout<<"find a track!!!"<<endl;
966 aMucTrackCol->add(aTrack);
967 TrackFinding(aTrack);
968 p3DRoadC->add(road3D);
969
970 ////////////record strip info in this track//////////////
971
972 vector<MucRecHit*> attachedHits = aTrack->GetHits();
973 vector<MucRecHit*> expectedHits = aTrack->GetExpectedHits();
974 vector<float> distanceHits = aTrack->getDistHits();
975
976 for(int i=0; i< expectedHits.size(); i++)
977 {
978 MucRecHit *ihit = expectedHits[i];
979 //cout<<"expected Hits: "<<ihit->Part()<<" "<<ihit->Seg()<<" "<<ihit->Gap()<<" "<<ihit->Strip()<<endl;
980 }
981
982 vector<int> multiHit;
983 for(int i=0; i< attachedHits.size(); i++)
984 {
985 MucRecHit *ihit = attachedHits[i];
986 //cout<<"attached Hits: "<<ihit->Part()<<" "<<ihit->Seg()<<" "<<ihit->Gap()<<" "<<ihit->Strip()<<" hitmode: "<<ihit->GetHitMode()<<endl;
987 //calc multiplicity hits;
988 int hitnum = 0;
989 for(int k=0; k < attachedHits.size(); k++){
990 MucRecHit *khit = attachedHits[k];
991 if((ihit->Part()==khit->Part())&&(ihit->Seg()==khit->Seg())&&(ihit->Gap()==khit->Gap()))
992 hitnum++;
993 }
994 multiHit.push_back(hitnum);
995 //cout<<"multi hit: "<<hitnum<<" "<<multiHit[i]<<endl;
996
997 }
998
999 for(int i=0; i< expectedHits.size(); i++)
1000 { //calc distance between attached hits and expected hits
1001
1002 MucRecHit *ihit = expectedHits[i];
1003 //cout<<"attached Hits: "<<ihit->Part()<<" "<<ihit->Seg()<<" "<<ihit->Gap()<<" "<<ihit->Strip()<<endl;
1004
1005 int diff = -999;
1006
1007 for(int j=0; j< attachedHits.size(); j++){
1008 MucRecHit *jhit = attachedHits[j];
1009
1010 // if(attachedHits.size()!=distanceHits.size())cout<<"attached hits size no same as disthits!!!"<<endl;
1011
1012 if((jhit->Part()==ihit->Part())&&(jhit->Seg()==ihit->Seg())&&(jhit->Gap()==ihit->Gap())&&attachedHits.size()==distanceHits.size())
1013 { // same gap, cale distance
1014 diff = ihit->Strip() - jhit->Strip();
1015 //cout<<"diff = "<<diff<<endl;
1016
1017 if(m_NtOutput>=2){
1018
1019 m_part = ihit->Part(); m_seg = ihit->Seg(); m_gap = ihit->Gap();
1020 m_strip = jhit->Strip();
1021 m_diff = diff;
1022 m_dist = distanceHits[j];
1023 //cout<<"distance = "<<m_dist<<endl;
1024
1025 m_angle_cosmic = -999;
1026 m_angle_updown = -999;
1027 //m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1028 //m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1029 //m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1030 m_ngapwithhits = aTrack->numLayers();
1031 m_nhit = aTrack->numHits();
1032 m_maxhit = aTrack->maxHitsInLayer();
1033 m_multihit = multiHit[j];
1034 m_run = eventHeader->runNumber();
1035 m_event = eventHeader->eventNumber();
1036
1037 m_tuple->write();
1038 }
1039 }
1040
1041
1042 }
1043
1044
1045
1046 if(diff == -999) { // to calc effi of this strip
1047 if(m_NtOutput>=2){
1048 m_part = ihit->Part(); m_seg = ihit->Seg(); m_gap = ihit->Gap();
1049 m_strip = ihit->Strip();
1050 m_diff = diff;
1051 m_dist = -999;
1052 m_angle_updown = -999;
1053 m_angle_cosmic = -999;
1054 //m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1055 //m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1056 //m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1057 m_ngapwithhits = aTrack->numLayers();
1058 m_run = eventHeader->runNumber();
1059 m_event = eventHeader->eventNumber();
1060 //m_tuple->write();
1061 }
1062 }
1063 //if(diff != -999) cout<< "has hit in this layer"<<endl;
1064
1065 }
1066 ////////////record strip info in this track//////////////
1067 /*
1068 m_part = -999;
1069 m_seg = -999;
1070 m_gap = -999;
1071 m_strip= -999;
1072 m_diff = -999;
1073
1074 m_angle_updown = -999;
1075 m_angle_cosmic = cosmicMom.angle(aTrack->getMucMomentum());
1076 if(m_angle_cosmic>1.57) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
1077 m_run = eventHeader->runNumber();
1078 m_event = eventHeader->eventNumber();
1079
1080 double px,py,pz,p,theta,phi;
1081 px = (aTrack->getMucMomentum()).x();
1082 py = (aTrack->getMucMomentum()).y();
1083 pz = (aTrack->getMucMomentum()).z();
1084
1085 Hep3Vector rotate(-px,pz,py);
1086 theta = rotate.theta();
1087 phi = rotate.phi();
1088
1089
1090 m_px = px; m_py = py; m_pz = pz;
1091 m_theta = theta; m_phi = phi;
1092 m_theta_pipe = (aTrack->getMucMomentum()).theta();
1093 m_phi_pipe = (aTrack->getMucMomentum()).phi();
1094 //m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1095 //m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1096 //////////if(m_py>0)m_tuple->write();
1097
1098 */
1099
1100 }
1101 else {
1102 //cout << "Delete a 3D Road ... " << endl;
1103 delete road3D;
1104 // don't keep it if it's not a good condidate
1105 }
1106 } // for ( int iRoad1 ...
1107 } // for ( int iRoad0 ..
1108
1109
1110 //for cosmic ray, to combine 2 track to 1
1111 RecMucTrack *aaTrack = 0;
1112 RecMucTrack *bbTrack = 0;
1113
1114 int hasMucUp = 0;
1115 int hasMucDown = 0;
1116 for(int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
1117 aaTrack = (*aMucTrackCol)[iTrack];
1118 if((aaTrack->getMucMomentum()).phi()<3.1415926&&(aaTrack->getMucMomentum()).phi()>0) hasMucUp++;
1119 else hasMucDown++;
1120
1121
1122 double px,py,pz,p,theta,phi;
1123 px = (aaTrack->getMucMomentum()).x();
1124 py = (aaTrack->getMucMomentum()).y();
1125 pz = (aaTrack->getMucMomentum()).z();
1126
1127 if(py<0)continue;
1128
1129 if(m_NtOutput>=1){
1130
1131 m_angle_updown = -999;
1132 m_angle_cosmic = cosmicMom.angle(aaTrack->getMucMomentum());
1133 if(m_angle_cosmic>1.57) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
1134 m_run = eventHeader->runNumber();
1135 m_event = eventHeader->eventNumber();
1136
1137 Hep3Vector rotate(-px,pz,py);
1138 theta = rotate.theta();
1139 phi = rotate.phi();
1140
1141 m_px = px; m_py = py; m_pz = pz;
1142 m_theta = theta; m_phi = phi;
1143 m_theta_pipe = (aaTrack->getMucMomentum()).theta();
1144 m_phi_pipe = (aaTrack->getMucMomentum()).phi();
1145
1146 //if(fabs(m_phi_pipe*57.2958-90)>3)cout<<"px,y,z = "<<m_px<<" "<<m_py<<" "<<m_pz<<endl;
1147
1148 //calc proj point in y=0 plane
1149 Hep3Vector mucPos = aaTrack->getMucPos();
1150 double posx, posy, posz;
1151 posx = mucPos.x(); posy = mucPos.y(); posz = mucPos.z();
1152 //double projx, projz;
1153 m_projx = -999; m_projz = -999;
1154 if(py!=0){
1155 m_projx = posx - px/py*posy;
1156 m_projz = posz - pz/py*posy;
1157 }
1158 //cout<<"projection: "<<projx<<" "<<projz<<endl;
1159 }
1160
1161 }
1162 if(m_NtOutput>=1){
1163 m_mucUp = hasMucUp; m_mucDown = hasMucDown;
1164 m_tuple->write();
1165 }
1166
1167 int forCosmic = 0;
1168 if(aMucTrackCol->size()>=2 && forCosmic == 1){
1169 for(int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
1170 log << MSG::DEBUG << "iTrack " << iTrack << " / " <<(int)aMucTrackCol->size()<<endreq;
1171 aaTrack = (*aMucTrackCol)[iTrack];
1172 if(aaTrack->trackId()>=0) continue; // this track has been used
1173 aaTrack->setTrackId(iTrack);
1174 //cout<<"atrack set index "<<iTrack<<endl;
1175 for(int jTrack = iTrack+1; jTrack < (int)aMucTrackCol->size(); jTrack++){
1176 bbTrack = (*aMucTrackCol)[jTrack];
1177
1178 Hep3Vector mom_a = aaTrack->getMucMomentum();
1179 Hep3Vector mom_b = bbTrack->getMucMomentum();
1180
1181 //cout<<"angle is : "<<mom_a.angle(mom_b)<<endl;
1182 if(fabs(mom_a.angle(mom_b) - 3.1415926)<0.2)
1183 {
1184 bbTrack->setTrackId(iTrack);
1185 //cout<<"btrack set index "<<iTrack<<endl;
1186 //cout<<"find one cosmic ray"<<endl;
1187
1188 //cout<<"angle = "<<cosmicMom.angle(mom_a)<<" "<<cosmicMom.angle(mom_b)<<endl;
1189
1190 }
1191
1192 if(m_NtOutput>=1){
1193 m_angle_cosmic = cosmicMom.angle(mom_a);
1194 if(cosmicMom.angle(mom_a)>1.57) m_angle_cosmic = 3.14159265 - cosmicMom.angle(mom_a);
1195
1196 m_angle_updown = fabs(mom_a.angle(mom_b) - 3.1415926);
1197 m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1198 m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1199 m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1200
1201 //m_tuple->write();
1202 }
1203 }
1204
1205 }
1206
1207
1208 }
1209
1210 if( p3DRoadC->size() !=0 ) {
1211 log<<MSG::INFO << "In 3DRoad container : "
1212 << " Num of 3DRoad = " << p3DRoadC->size() <<endreq;
1213
1214 int print2DRoadInfo = 0;
1215 if (print2DRoadInfo == 1) {
1216 for ( int iRoad = 0; iRoad < (int)p3DRoadC->size(); iRoad++) {
1217 MucRec3DRoad *road = (*p3DRoadC)[iRoad];
1218 cout << endl << " " << iRoad << "th 3DRoad :" << endl
1219 << " Part = " << road->GetPart() << endl
1220 << " Seg = " << road->GetSeg() << endl
1221 << " NumGapsWithHits = " << road->GetNGapsWithHits() << endl
1222 << " TotalHits = " << road->GetTotalHits() << endl
1223 << " MaxHitsPerGap = " << road->GetMaxHitsPerGap() << endl
1224 << " LastGapDelta = " << road->GetLastGapDelta() << endl
1225 << " TotalHitsDelta = " << road->GetTotalHitsDelta() << endl
1226 << " DegreesOfFreedom = " << road->GetDegreesOfFreedom() << endl
1227 << " ReducedChiSquare = " << road->GetReducedChiSquare() << endl
1228 << " SlopeZX = " << road->GetSlopeZX() << endl
1229 << " InterceptZX = " << road->GetInterceptZX() << endl
1230 << " SlopeZY = " << road->GetSlopeZY() << endl
1231 << " InterceptZY = " << road->GetInterceptZY() << endl
1232 << " Hits Info : " << endl;
1233 //road->PrintHitsInfo();
1234 }
1235 }
1236
1237 m_NEventReco ++;
1238 }
1239
1240 //delete p3DRoadC
1241 for(int i = 0 ; i < p3DRoadC->size(); i++)
1242 delete (*p3DRoadC)[i];
1243 for(int i = 0 ; i < p2DRoad0C->size(); i++)
1244 delete (*p2DRoad0C)[i];
1245 for(int i = 0 ; i < p2DRoad1C->size(); i++)
1246 delete (*p2DRoad1C)[i];
1247
1248 p3DRoadC->clear();
1249 p2DRoad0C->clear();
1250 p2DRoad1C->clear();
1251 delete p3DRoadC;
1252 delete p2DRoad0C;
1253 delete p2DRoad1C;
1254 return StatusCode::SUCCESS;
1255}
Double_t x[10]
ObjectVector< MucRec2DRoad > MucRec2DRoadContainer
Definition: MucRec2DRoad.h:234
ObjectVector< MucRec3DRoad > MucRec3DRoadContainer
Definition: MucRec3DRoad.h:201
ObjectVector< MucRecHit > MucRecHitCol
Definition: MucRecHit.h:127
const int kMaxDeltaLastGap
const int kMinLastGap3D
const int kMinLastGap2D
const int kMinSharedHits2D
const int kMaxDeltaTotalHits
const int kNSeedLoops
const float kMaxYChisq
const float kWindowSize[3][9]
const int kSearchOrder[kNSeedLoops][3][2][5]
const float kMaxXChisq
const int kMaxSkippedGaps
const int kSearchLength[kNSeedLoops][3][2]
const int kMinFiredGaps
ObjectVector< RecMucTrack > RecMucTrackCol
Definition: RecMucTrack.h:394
IMessageSvc * msgSvc()
int numHits() const
Definition: DstMucTrack.h:41
int trackId() const
Definition: DstMucTrack.h:32
int maxHitsInLayer() const
Definition: DstMucTrack.h:43
void setId(int id)
Definition: DstMucTrack.h:76
int numLayers() const
Definition: DstMucTrack.h:42
int Orient() const
Definition: MucGeoGap.h:108
static int barrel_ec(const Identifier &id)
Values of different levels.
Definition: MucID.cxx:41
static int layer(const Identifier &id)
Definition: MucID.cxx:61
static int channel(const Identifier &id)
Definition: MucID.cxx:71
static int segment(const Identifier &id)
Definition: MucID.cxx:51
static value_type getPartNum()
Definition: MucID.cxx:159
static value_type getSegNum(int part)
Definition: MucID.cxx:164
int GetNGapsWithHits() const
How many gaps provide hits attached to this road?
int GetTotalHits() const
How many hits in all does this road contain?
float GetReducedChiSquare() const
Chi-square parameter (per degree of freedom) of the trajectory fit.
float GetIntercept() const
Intercept of trajectory.
void AttachHit(MucRecHit *hit)
Attach the given hit to this road.
int GetLastGap() const
Which gap is the last one with hits attached to this road?
void AttachHitNoFit(MucRecHit *hit)
Attach the given hit to this road, but not fit this road.
float GetSlope() const
Slope of trajectory.
void SetMaxNSkippedGaps(const int &nGaps)
int GetPart() const
In which part was this road found?
float GetHitDistance(const MucRecHit *hit)
Distance to a hit.
int GetDegreesOfFreedom() const
How many degrees of freedom in the trajectory fit?
vector< MucRecHit * > GetHits() const
int GetSeg() const
In which segment was this road found?
int GetOrient() const
In which orientation was this road found?
float GetSlopeZX() const
Get Z-X dimension slope.
float GetSlopeZY() const
Get Z-Y dimension slope.
void TransformPhiRToXY(const float &vk, const float &vr, const float &k0, const float &r0, float &vx, float &vy, float &x0, float &y0) const
Where does the trajectory of this road intersect the reference plane?
int GetLastGapDelta() const
Difference between the last gap in the two 1-D roads.
int GetPart() const
In which part was this road found?
int GetLastGap() const
Which gap is the last one with hits attached to this road?
int GetTotalHitsDelta() const
Difference between the number of hits in the two 1-D roads.
int GetTotalHits() const
How many hits in all does this road contain?
float GetInterceptZY() const
Get Z-Y dimension intercept.
void SetSimpleFitParams(const float &m_SlopeZX, const float &m_InterceptZX, const float &m_SlopeZY, const float &m_InterceptZY)
set the fit parameters : slope and intercept for XZ and YZ.
int GetSeg() const
In which segment was this road found?
int GetDegreesOfFreedom() const
How many degrees of freedom in the trajectory fit?
void ProjectWithSigma(const int &gap, float &x, float &y, float &z, float &sigmaX, float &sigmaY, float &sigmaZ)
Where does the trajectory of this road intersect a specific gap?
float GetInterceptZX() const
Get Z-X dimension intercept.
int GetNGapsWithHits() const
How many gaps provide hits attached to this road?
float GetReducedChiSquare() const
Chi-square parameter (per degree of freedom) of the trajectory fit.
int GetMaxHitsPerGap() const
How many hits were attached in the gap with the most attached hits?
void Clear()
Remove all hit objects from the container, and destroy them.
MucRecHit * GetHit(const MucRecHitID hitID)
Get a MucRecHit object by hit identifier.
void AddHit(const Identifier id)
MucRecHitCol * GetMucRecHitCol()
Get MucRecHitCol pointer.
void SetMucRecHitCol(MucRecHitCol *p)
int GetGapHitCount(const MucRecHitID gapID)
How many hits are there in this gap?
int Seg() const
Get Seg.
Definition: MucRecHit.h:74
void SetHitSeed(int seed)
Definition: MucRecHit.h:98
int GetHitMode() const
Definition: MucRecHit.h:96
MucGeoGap * GetGap() const
Get geometry data for the gap containing this hit.
Definition: MucRecHit.h:83
int Part() const
Get Part.
Definition: MucRecHit.h:71
int Gap() const
Get Gap.
Definition: MucRecHit.h:77
int Strip() const
Get Strip.
Definition: MucRecHit.h:80
void SetHitMode(int recmode)
Definition: MucRecHit.h:94
void TrackFinding(RecMucTrack *aTrack)
Hep3Vector getMucPos() const
start position of this track in Muc.
Definition: RecMucTrack.h:198
void SetExtMucPos(const float x, const float y, const float z)
set start position of ext track in Muc. (compute from MdcPos MdcMomentum or get from ExtTrack)
void SetCurrentDir(const float x, const float y, const float z)
set current direction of the trajectory.
void setTrackId(const int trackId)
set the index for this track.
void SetMucMomentum(const float px, const float py, const float pz)
set start moment of the track in Muc.
void SetExtMucMomentum(const float px, const float py, const float pz)
set start moment of ext track in Muc.
vector< MucRecHit * > GetHits() const
Get all hits on this track.
Hep3Vector getMucMomentum() const
Start momentum of this track in Muc.
Definition: RecMucTrack.h:203
void SetCurrentPos(const float x, const float y, const float z)
set current position of the trajectory.
vector< MucRecHit * > GetExpectedHits() const
void SetRecMode(int recmode)
Definition: RecMucTrack.h:254
void SetMucPos(const float x, const float y, const float z)
set start position of the track in Muc. (after line fit and correction)
vector< float > getDistHits() const
Definition: RecMucTrack.h:311
uint32_t count(const node_t &list)
Definition: node.cxx:42

◆ finalize()

StatusCode MucRecRoadFinder::finalize ( )

Definition at line 1258 of file MucRecRoadFinder.cxx.

1259{
1260 MsgStream log(msgSvc(), name());
1261 log << MSG::INFO << "in finalize()" << endreq;
1262
1263 //cout << m_NHitsLostTotal << " of " << m_NHitsTotal << " total hits" << endl;
1264 //for(int i = 0; i < 20; i++) cout << "lost " << i << " hits event " << m_NHitsLost[i] << endl;
1265 //for(int i = 0; i < 9; i++) cout << "lost on gap " << i << " is " << m_NHitsLostInGap[i] << endl;
1266
1267 return StatusCode::SUCCESS;
1268}

◆ initialize()

StatusCode MucRecRoadFinder::initialize ( )

Definition at line 64 of file MucRecRoadFinder.cxx.

65{
66 MsgStream log(msgSvc(), name());
67 log << MSG::INFO << "in initialize()" << endreq;
68
69 m_NHitsTotal = 0;
70 m_NHitsLostTotal = 0;
71 for(int i = 0; i < 20; i++) m_NHitsLost.push_back(0);
72 for(int i = 0; i < 10; i++) m_NHitsLostInGap.push_back(0);
73
74 m_NEvent = 0;
75 m_NEventWithHit = 0;
76 m_NEventReco = 0;
77
78 IMucGeomSvc* mucGeomSvc;
79 StatusCode sc = service("MucGeomSvc", mucGeomSvc);
80 if (sc == StatusCode::SUCCESS) {
81 mucGeomSvc->Dump();
82 //cout<<"1st wire id:"<<mucGeomSvc->Wire(0)->Id()<<endl;
83 //cout<<"2nd wire lyr id:"<<mucGeomSvc->Wire(1)->Lyr()->Id()<<endl;
84 //cout<<"6860th wire lyr id:"<<mucGeomSvc->Wire(6859)->Lyr()->Id()<<endl;
85 } else {
86 return StatusCode::FAILURE;
87 }
88
89 aMucRecHitContainer = 0;
90
91 if(m_NtOutput>=1){
92 NTuplePtr nt1(ntupleSvc(), "FILE401/T");
93
94 if ( nt1 ) { m_tuple = nt1;}
95 else {
96 // m_tuple = ntupleSvc()->book ("MyTuples/1", CLID_RowWiseTuple, "MdcTrkRecon N-Tuple");
97 m_tuple = ntupleSvc()->book ("FILE401/T", CLID_RowWiseTuple, "MucTrkRecon N-Tuple");
98 if ( m_tuple ) {
99 sc = m_tuple->addItem ("part", m_part);
100 sc = m_tuple->addItem ("seg", m_seg);
101 sc = m_tuple->addItem ("gap", m_gap);
102 sc = m_tuple->addItem ("strip", m_strip);
103 sc = m_tuple->addItem ("diff", m_diff);
104 sc = m_tuple->addItem ("dist", m_dist);
105 sc = m_tuple->addItem ("run", m_run);
106 sc = m_tuple->addItem ("event", m_event);
107 sc = m_tuple->addItem ("ngap", m_ngapwithhits);
108 sc = m_tuple->addItem ("nhit", m_nhit);
109 sc = m_tuple->addItem ("maxhit", m_maxhit);
110 sc = m_tuple->addItem ("multihit",m_multihit);
111 sc = m_tuple->addItem ("angleCosmic",m_angle_cosmic);
112 sc = m_tuple->addItem ("angleUpdown",m_angle_updown);
113 sc = m_tuple->addItem ("px",m_px);
114 sc = m_tuple->addItem ("py",m_py);
115 sc = m_tuple->addItem ("pz",m_pz);
116 sc = m_tuple->addItem ("theta",m_theta);
117 sc = m_tuple->addItem ("phi",m_phi);
118 sc = m_tuple->addItem ("theta_pipe",m_theta_pipe);
119 sc = m_tuple->addItem ("phi_pipe",m_phi_pipe);
120 sc = m_tuple->addItem ("pxmc",m_px_mc);
121 sc = m_tuple->addItem ("pymc",m_py_mc);
122 sc = m_tuple->addItem ("pzmc",m_pz_mc);
123 sc = m_tuple->addItem ("thetamc",m_theta_mc);
124 sc = m_tuple->addItem ("phimc",m_phi_mc);
125 sc = m_tuple->addItem ("thetamc_pipe",m_theta_mc_pipe);
126 sc = m_tuple->addItem ("phimc_pipe",m_phi_mc_pipe);
127 sc = m_tuple->addItem ("emcUp",m_emcUp);
128 sc = m_tuple->addItem ("emcDown",m_emcDown);
129 sc = m_tuple->addItem ("mucUp",m_mucUp);
130 sc = m_tuple->addItem ("mucDown",m_mucDown);
131 sc = m_tuple->addItem ("projx",m_projx);
132 sc = m_tuple->addItem ("projz",m_projz);
133
134 }
135 else { // did not manage to book the N tuple....
136 log << MSG::ERROR << " Cannot book N-tuple:" << long(m_tuple) << endmsg;
137 //return StatusCode::FAILURE;
138 }
139 }
140 }
141
142 return StatusCode::SUCCESS;
143}
INTupleSvc * ntupleSvc()
virtual void Dump()=0

◆ TrackFinding()

void MucRecRoadFinder::TrackFinding ( RecMucTrack aTrack)

Definition at line 1271 of file MucRecRoadFinder.cxx.

1272{
1273 MsgStream log(msgSvc(), name());
1274
1275 Hep3Vector currentPos = aTrack->GetCurrentPos();
1276 Hep3Vector currentDir = aTrack->GetCurrentDir();
1277 // if(currentPos.mag() < kMinor) {
1278 // log << MSG::WARNING << "No MUC intersection in track " << endreq;
1279 // continue;
1280 // }
1281
1282 int firstHitFound[2] = { 0, 0}; // Has the fist position in this orient determined? if so, could CorrectDirection()
1283 int firstHitGap[2] = {-1, -1}; // When the fist position in this orient determined, the gap it is on
1284 for(int partSeq = 0; partSeq < (int)MucID::getPartNum(); partSeq++) {
1285 int iPart = kPartSeq[partSeq];
1286 for(int iGap = 0; iGap < (int)MucID::getGapNum(iPart); iGap++) {
1287 int seg = -1;
1288 int orient = MucGeoGeneral::Instance()->GetGap(iPart, 0, iGap)->Orient();;
1289
1290 float xInsct, yInsct, zInsct;
1291 aTrack->Project(iPart, iGap, xInsct, yInsct, zInsct, seg);
1292 if(m_MsOutput) cout<<"part "<<iPart<<" gap "<<iGap<<" x "<<xInsct<<" y "<<yInsct<<" z "<<zInsct<<" seg "<<seg<<endl;
1293
1294 if(seg == -1) {
1295 //log << MSG::DEBUG << "no intersection with part " << iPart
1296 // << " gap " << iGap << " in this track !" << endl;
1297 continue;
1298 }
1299
1300 aTrack->SetCurrentInsct(xInsct, yInsct, zInsct);
1301
1302 for(int iDeltaSeg = 0; iDeltaSeg < kNSegSearch; iDeltaSeg++) {
1303 int iSeg = seg + kDeltaSeg[iDeltaSeg]; // also find on neighbor seg;
1304 if(iSeg < 0) iSeg += MucID::getSegNum(iPart);
1305 if(iSeg > (int)MucID::getSegNum(iPart) - 1) iSeg -= MucID::getSegNum(iPart);
1306
1307 float window = kWindowSize[iPart][iGap];
1308
1309 for (int iHit = 0; iHit < aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap); iHit++) {
1310 log << MSG::DEBUG << "iSeg " << iSeg << " iHit " << iHit << endreq;
1311 MucRecHit* pHit = aMucRecHitContainer->GetHit(iPart, iSeg, iGap, iHit);
1312 //cout<< "strip " << pHit->Strip() << " center " << pHit->GetCenterPos() << endl;
1313
1314 if (!pHit) {
1315 log << MSG::WARNING << "MucRecTrkExt: null pointer to pHit" << endreq;
1316 continue;
1317 }
1318 else {
1319
1320 //this algo use with ext and this hit has been used before;
1321 if(pHit->GetHitMode() != -1 && pHit->GetHitMode() != 3) continue;
1322
1323 // Get the displacement of hit pHit to intersection
1324 float dX = aTrack->GetHitDistance(pHit);
1325 log << MSG::DEBUG << "distance = " << setw(8) << dX << " size " << setw(4) << window << endreq;
1326
1327 //cout<<"dX= "<<dX<<" window="<<window<<endl;
1328
1329 if (dX < window) {
1330 // Attach the hit if it exists
1331 //cout << "meet window " << pHit->GetSoftID() << endl;
1332 //****************if this if emc track, we abondon used hit in mdc*******************
1333 //if(m_emcrec == 1 )
1334 if(aTrack->GetRecMode() == 0) {
1335 pHit->SetHitMode(1); //mdc ext
1336 aTrack->AttachHit(pHit);
1337 //cout<<"in MucRecTrkExt: trackmode==0 so mdc ext "<<iPart<<" "<<iSeg<<" "<<iGap<<" "<<iHit<<endl;
1338 }
1339 if(aTrack->GetRecMode() == 1) {
1340 //cout<<"in MucRecTrkExt: HitMode = "<<pHit->GetHitMode()<<" part: "<<iPart<<" "<<iSeg<<" "<<iGap<<" "<<iHit<<endl;
1341 if(pHit->GetHitMode()!=1) {
1342 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1343 pHit->SetHitMode(2); //emc ext
1344 }
1345 }
1346 if(aTrack->GetRecMode() == 2) {
1347 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1348 //pHit->SetHitMode(2); //emc ext
1349 }
1350 if(aTrack->GetRecMode() == 3) {
1351 if(pHit->GetHitMode()!=1) {
1352 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1353 pHit->SetHitMode(3); //emc ext
1354 }
1355 }
1356
1357 if (firstHitGap[orient] == -1) firstHitGap[orient] = iGap;
1358 firstHitFound[orient] = 1;
1359 //cout << "You could correct directon in orient " << orient << endl;
1360
1361 //cout<< " part " << iPart << " seg " << iSeg << " gap " << iGap
1362 // << " strip " << setw(2) << pHit->Strip() << " attatched" << endl;
1363
1364 log << MSG::DEBUG << " part " << iPart << " seg " << iSeg << " gap " << iGap
1365 << " strip " << setw(2) << pHit->Strip() << " attatched" << endreq;
1366 log << MSG::DEBUG << "current total hits " << aTrack->GetTotalHits() << endreq;
1367 }
1368 else {
1369 m_NHitsLostInGap[iGap]++;
1370 //log << MSG::DEBUG cout << " part " << iPart << " seg " << iSeg << " gap " << iGap
1371 // << " strip " << setw(2) << pHit->GetSoftID().GetStrip()
1372 // << " not attached !" << endreq;
1373 }
1374 }
1375 }
1376 aTrack->CalculateInsct(iPart, iSeg, iGap);
1377 }
1378
1379 if(m_onlyseedfit == 0) {//
1380 // When correct dir in the orient is permitted and this gap is not the gap first hit locates.
1381 if (firstHitFound[orient] && firstHitGap[orient] != iGap) aTrack->CorrectDir();
1382 aTrack->CorrectPos();
1383 //cout << "Current Intersection " << aTrack->GetCurrentInsct() << endl;
1384 //cout << "Current Direction " << aTrack->GetCurrentDir() << endl;
1385 aTrack->AttachInsct(aTrack->GetCurrentInsct());
1386 }// else; not correct pos & dir.
1387
1388 }
1389 }
1390 aTrack->LineFit(1);
1391 aTrack->ComputeTrackInfo(1);
1392 log << MSG::INFO << "Fit track done! trackIndex: " << aTrack->trackId() << ", mucId: " << aTrack->id() << ", RecMode: " << aTrack->GetRecMode() << endreq;
1393 //cout<<" in TrackFinding: depth= "<<aTrack->GetDepth()<<endl;
1394}
const int kNSegSearch
const int kPartSeq[3]
const int kDeltaSeg[kNSegSearch]
int id() const
Definition: DstMucTrack.h:33
MucGeoGap * GetGap(const int part, const int seg, const int gap) const
Get a pointer to the gap identified by (part,seg,gap).
static MucGeoGeneral * Instance()
Get a pointer to the single instance of MucGeoGeneral.
static value_type getGapNum(int part)
Definition: MucID.cxx:171
int GetTotalHits() const
How many hits in all does this track contain?
void LineFit(int fittingMethod)
Line fit with hits on a seg with max hits.
void CorrectPos()
Correct current position of this trajectory.
void CorrectDir()
Correct direction of this trajectory.
void ComputeTrackInfo(int fittingmethod)
Get corresponding monte carlo track pointer.
void AttachInsct(Hep3Vector insct)
Attach the intersection to this trajectory.
float GetHitDistance(const MucRecHit *hit)
Calculate the distance of the hit to the intersection in read direction.
int GetRecMode() const
Definition: RecMucTrack.h:256
Hep3Vector GetCurrentDir() const
Current direction.
Definition: RecMucTrack.h:212
Hep3Vector CalculateInsct(const int part, const int seg, const int gap)
Calculate intersection from all hits attached on this gap.
void Project(const int &part, const int &gap, float &x, float &y, float &z, int &seg)
Where does the trajectory of this track intersect a specific gap?
Hep3Vector GetCurrentInsct() const
Current intersection.
Definition: RecMucTrack.h:215
void AttachHit(MucRecHit *hit)
set corresponding monte carlo track pointer.
Hep3Vector GetCurrentPos() const
Current position.
Definition: RecMucTrack.h:209
void SetCurrentInsct(const float x, const float y, const float z)
set current intersection of the trajectory with strip plane.

Referenced by execute().


The documentation for this class was generated from the following files: