BOSS 7.1.2
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 51 of file MucRecRoadFinder.cxx.

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

◆ ~MucRecRoadFinder()

MucRecRoadFinder::~MucRecRoadFinder ( )
inline

Definition at line 32 of file MucRecRoadFinder.h.

32{};

Member Function Documentation

◆ execute()

StatusCode MucRecRoadFinder::execute ( )

Definition at line 173 of file MucRecRoadFinder.cxx.

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

◆ finalize()

StatusCode MucRecRoadFinder::finalize ( )

Definition at line 1304 of file MucRecRoadFinder.cxx.

1305{
1306 MsgStream log(msgSvc(), name());
1307 log << MSG::INFO << "in finalize()" << endreq;
1308
1309 //cout << m_NHitsLostTotal << " of " << m_NHitsTotal << " total hits" << endl;
1310 //for(int i = 0; i < 20; i++) cout << "lost " << i << " hits event " << m_NHitsLost[i] << endl;
1311 //for(int i = 0; i < 9; i++) cout << "lost on gap " << i << " is " << m_NHitsLostInGap[i] << endl;
1312
1313 return StatusCode::SUCCESS;
1314}

◆ initialize()

StatusCode MucRecRoadFinder::initialize ( )

Definition at line 68 of file MucRecRoadFinder.cxx.

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

◆ TrackFinding()

void MucRecRoadFinder::TrackFinding ( RecMucTrack * aTrack)

Definition at line 1317 of file MucRecRoadFinder.cxx.

1318{
1319 MsgStream log(msgSvc(), name());
1320
1321 Hep3Vector currentPos = aTrack->GetCurrentPos();
1322 Hep3Vector currentDir = aTrack->GetCurrentDir();
1323 // if(currentPos.mag() < kMinor) {
1324 // log << MSG::WARNING << "No MUC intersection in track " << endreq;
1325 // continue;
1326 // }
1327
1328 int firstHitFound[2] = { 0, 0}; // Has the fist position in this orient determined? if so, could CorrectDirection()
1329 int firstHitGap[2] = {-1, -1}; // When the fist position in this orient determined, the gap it is on
1330 for(int partSeq = 0; partSeq < (int)MucID::getPartNum(); partSeq++) {
1331 int iPart = kPartSeq[partSeq];
1332 for(int iGap = 0; iGap < (int)MucID::getGapNum(iPart); iGap++) {
1333 int seg = -1;
1334 int orient = MucGeoGeneral::Instance()->GetGap(iPart, 0, iGap)->Orient();;
1335
1336 float xInsct, yInsct, zInsct;
1337 aTrack->Project(iPart, iGap, xInsct, yInsct, zInsct, seg);
1338 if(m_MsOutput) cout<<"part "<<iPart<<" gap "<<iGap<<" x "<<xInsct<<" y "<<yInsct<<" z "<<zInsct<<" seg "<<seg<<endl;
1339
1340 if(seg == -1) {
1341 //log << MSG::DEBUG << "no intersection with part " << iPart
1342 // << " gap " << iGap << " in this track !" << endl;
1343 continue;
1344 }
1345
1346 aTrack->SetCurrentInsct(xInsct, yInsct, zInsct);
1347
1348 for(int iDeltaSeg = 0; iDeltaSeg < kNSegSearch; iDeltaSeg++) {
1349 int iSeg = seg + kDeltaSeg[iDeltaSeg]; // also find on neighbor seg;
1350 if(iSeg < 0) iSeg += MucID::getSegNum(iPart);
1351 if(iSeg > (int)MucID::getSegNum(iPart) - 1) iSeg -= MucID::getSegNum(iPart);
1352
1353 float window = kWindowSize[iPart][iGap];
1354
1355 for (int iHit = 0; iHit < aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap); iHit++) {
1356 log << MSG::DEBUG << "iSeg " << iSeg << " iHit " << iHit << endreq;
1357 MucRecHit* pHit = aMucRecHitContainer->GetHit(iPart, iSeg, iGap, iHit);
1358 //cout<< "strip " << pHit->Strip() << " center " << pHit->GetCenterPos() << endl;
1359
1360 if (!pHit) {
1361 log << MSG::WARNING << "MucRecTrkExt: null pointer to pHit" << endreq;
1362 continue;
1363 }
1364 else {
1365
1366 //this algo use with ext and this hit has been used before;
1367 if(pHit->GetHitMode() != -1 && pHit->GetHitMode() != 3) continue;
1368
1369 // Get the displacement of hit pHit to intersection
1370 float dX = aTrack->GetHitDistance(pHit);
1371 log << MSG::DEBUG << "distance = " << setw(8) << dX << " size " << setw(4) << window << endreq;
1372
1373 //cout<<"dX= "<<dX<<" window="<<window<<endl;
1374
1375 if (dX < window) {
1376 // Attach the hit if it exists
1377 //cout << "meet window " << pHit->GetSoftID() << endl;
1378 //****************if this if emc track, we abondon used hit in mdc*******************
1379 //if(m_emcrec == 1 )
1380 if(aTrack->GetRecMode() == 0) {
1381 pHit->SetHitMode(1); //mdc ext
1382 aTrack->AttachHit(pHit);
1383 //cout<<"in MucRecTrkExt: trackmode==0 so mdc ext "<<iPart<<" "<<iSeg<<" "<<iGap<<" "<<iHit<<endl;
1384 }
1385 if(aTrack->GetRecMode() == 1) {
1386 //cout<<"in MucRecTrkExt: HitMode = "<<pHit->GetHitMode()<<" part: "<<iPart<<" "<<iSeg<<" "<<iGap<<" "<<iHit<<endl;
1387 if(pHit->GetHitMode()!=1) {
1388 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1389 pHit->SetHitMode(2); //emc ext
1390 }
1391 }
1392 if(aTrack->GetRecMode() == 2) {
1393 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1394 //pHit->SetHitMode(2); //emc ext
1395 }
1396 if(aTrack->GetRecMode() == 3) {
1397 if(pHit->GetHitMode()!=1) {
1398 aTrack->AttachHit(pHit); //this hit has not been used by mdc ext
1399 pHit->SetHitMode(3); //emc ext
1400 }
1401 }
1402
1403 if (firstHitGap[orient] == -1) firstHitGap[orient] = iGap;
1404 firstHitFound[orient] = 1;
1405 //cout << "You could correct directon in orient " << orient << endl;
1406
1407 //cout<< " part " << iPart << " seg " << iSeg << " gap " << iGap
1408 // << " strip " << setw(2) << pHit->Strip() << " attatched" << endl;
1409
1410 log << MSG::DEBUG << " part " << iPart << " seg " << iSeg << " gap " << iGap
1411 << " strip " << setw(2) << pHit->Strip() << " attatched" << endreq;
1412 log << MSG::DEBUG << "current total hits " << aTrack->GetTotalHits() << endreq;
1413 }
1414 else {
1415 m_NHitsLostInGap[iGap]++;
1416 //log << MSG::DEBUG cout << " part " << iPart << " seg " << iSeg << " gap " << iGap
1417 // << " strip " << setw(2) << pHit->GetSoftID().GetStrip()
1418 // << " not attached !" << endreq;
1419 }
1420 }
1421 }
1422 aTrack->CalculateInsct(iPart, iSeg, iGap);
1423 }
1424
1425 if(m_onlyseedfit == 0) {//
1426 // When correct dir in the orient is permitted and this gap is not the gap first hit locates.
1427 if (firstHitFound[orient] && firstHitGap[orient] != iGap) aTrack->CorrectDir();
1428 aTrack->CorrectPos();
1429 //cout << "Current Intersection " << aTrack->GetCurrentInsct() << endl;
1430 //cout << "Current Direction " << aTrack->GetCurrentDir() << endl;
1431 aTrack->AttachInsct(aTrack->GetCurrentInsct());
1432 }// else; not correct pos & dir.
1433
1434 }
1435 }
1436 aTrack->LineFit(1);
1437 aTrack->ComputeTrackInfo(1);
1438 log << MSG::INFO << "Fit track done! trackIndex: " << aTrack->trackId() << ", mucId: " << aTrack->id() << ", RecMode: " << aTrack->GetRecMode() << endreq;
1439 //cout<<" in TrackFinding: depth= "<<aTrack->GetDepth()<<endl;
1440}
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
Hep3Vector GetCurrentDir() const
Current direction.
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.
void AttachHit(MucRecHit *hit)
set corresponding monte carlo track pointer.
Hep3Vector GetCurrentPos() const
Current position.
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: