70 #if ROOT_VERSION_CODE < 331013
76 #include "TDataSetIter.h"
77 #include "StMessMgr.h"
78 #include "StChainOpt.h"
79 #include "SystemOfUnits.h"
80 #include "StMemStat.h"
81 #include "PhysicalConstants.h"
82 #include "StDetectorId.h"
83 #include "StEventTypes.h"
84 #include "Sti/Base/EditableFilter.h"
85 #include "Sti/StiKalmanTrackFinder.h"
86 #include "Sti/StiKalmanTrackFitter.h"
87 #include "Sti/StiTrackContainer.h"
88 #include "Sti/StiDefaultTrackFilter.h"
89 #include "Sti/StiMasterDetectorBuilder.h"
90 #include "Sti/Star/StiStarDetectorGroup.h"
91 #include "StiTpc/StiTpcDetectorGroup.h"
92 #include "StiTpc/StiTpcHitLoader.h"
93 #include "StiSvt/StiSvtDetectorGroup.h"
94 #include "StiSsd/StiSsdDetectorGroup.h"
95 #include "StiSsd/StiSstDetectorGroup.h"
96 #include "StiPxl/StiPxlDetectorGroup.h"
97 #include "Sti/StiKalmanTrackNode.h"
99 #include "Sti/StiVertexFinder.h"
100 #include "Sti/StiDetectorContainer.h"
101 #include "StiMaker/StiStEventFiller.h"
103 #include "StiMaker.h"
106 #include "StDetectorDbMaker/StiKalmanTrackFinderParameters.h"
107 #include "StDetectorDbMaker/StiKalmanTrackFitterParameters.h"
109 #include "TObjString.h"
111 #include "StDetectorDbMaker/StiHitErrorCalculator.h"
114 #include "StiIst/StiIstDetectorGroup.h"
117 #include "StiUtilities/StiPullEvent.h"
118 #include "TDataSet.h"
119 #include "TGeometry.h"
121 #include "StiDetectorVolume.h"
122 #include "StarMagField.h"
124 #include "StG2TrackVertexMap.h"
126 #include "StTpcDb/StTpcDb.h"
127 #include "StSsdDbMaker/StSsdDbMaker.h"
128 #include "StSsdDbMaker/StSstDbMaker.h"
129 #include "StSvtDbMaker/StSvtDbMaker.h"
134 static const float MIN_VTX_ERR2 = 1e-4*1e-4;
135 enum { kHitTimg,kGloTimg,kVtxTimg,kPriTimg,kFilTimg};
140 StiMaker::StiMaker(
const Char_t *name) :
152 _loaderTrackFilter(0),
157 memset(mTimg,0,
sizeof(mTimg));
158 cout <<
"StiMaker::StiMaker() -I- Starting"<<endl;
159 mPullFile=0; mPullEvent=0;mPullTTree=0;
160 memset(mPullHits,0,
sizeof(mPullHits));
161 mTotPrimTks[0]=mTotPrimTks[1]=0;
163 _toolkit = StiToolkit::instance();
164 SetAttr(
"useTpc" ,kTRUE);
165 SetAttr(
"activeTpc" ,kTRUE);
167 SetAttr(
"useSvt" ,kTRUE);
168 SetAttr(
"useSsd" ,kTRUE);
176 SetAttr(
"useEventFiller" ,kTRUE);
177 SetAttr(
"useTracker" ,kTRUE);
178 SetAttr(
"useVertexFinder" ,kTRUE);
179 SetAttr(
"Alignment" ,kFALSE);
180 if (strstr(gSystem->Getenv(
"STAR"),
".DEV"))
181 SetAttr(
"useAux",kTRUE);
185 StiMaker::~StiMaker()
187 cout <<
"StiMaker::~StiMaker() -I- Started/Done"<<endl;
191 void StiMaker::Clear(
const char*)
193 if (_tracker ) _tracker->
clear();
194 if (mPullEvent) mPullEvent->Clear();
204 if (Debug()) mPullTTree->Print();
206 TFile *tfile = mPullTTree->GetCurrentFile();
216 static const char *timg[] = {
"HitLoa",
"GlobFnd",
"VtxFnd",
"PriFnd",
"FilFnd",0};
218 for (
int i=0;timg[i];i++) {
219 Info(
"Timing",
"%s(%d) \tCpuTime = %6.2f seconds,\tPerEvent = %g seconds"
220 ,timg[i],mTimg[i]->Counter(),mTimg[i]->CpuTime()
221 ,mTimg[i]->CpuTime()/mTimg[i]->Counter());
223 if (_tracker) _tracker->
finish();
229 Int_t StiMaker::Init()
233 StiTimer::Init(
"StiTrackFinder::find() TIMING"
234 ,StiTimer::fgFindTimer,StiTimer::fgFindTally);
235 if (IAttr(
"Alignment")) SetAttr(
".Privilege",kTRUE);
236 _loaderHitFilter = 0;
237 mTotPrimTks[1] = IAttr(
"maxTotPrims");
238 if (*SAttr(
"maxRefiter")) StiKalmanTrack::setMaxRefiter(IAttr(
"maxRefiter"));
241 if (*SAttr(
"maxRefiter")) StiKalmanTrack::setMaxRefiter(IAttr(
"maxRefiter"));
242 if (IAttr(
"useTiming")) {
243 for (
int it=0;it<(int)(
sizeof(mTimg)/
sizeof(mTimg[0]));it++){
244 mTimg[it]=
new TStopwatch(); mTimg[it]->Stop();
247 return StMaker::Init();
251 Int_t StiMaker::InitDetectors()
254 cout<<
"StiMaker::InitDetectors() -I- Adding detector group:Star"<<endl;
256 if (IAttr(
"useTpc") && gStTpcDb)
258 cout<<
"StiMaker::InitDetectors() -I- Adding detector group:TPC"<<endl;
262 if (IAttr(
"activeSvt") || IAttr(
"activeSsd") || IAttr(
"skip1row")) {
263 hitLoader->setMinRow(2);
265 if (IAttr(
"EastOff")) {
266 hitLoader->setMinSector(1);
267 hitLoader->setMaxSector(12);
269 if (IAttr(
"WestOff")) {
270 hitLoader->setMinSector(13);
271 hitLoader->setMaxSector(24);
273 cout <<
"StiMaker::InitDetectors() -I- use hits in sectors["
274 << hitLoader->minSector() <<
"," << hitLoader->maxSector() <<
"] and rows["
275 << hitLoader->minRow() <<
",*]" << endl;
276 if (IAttr(
"laserIT")) {
277 StiKalmanTrackNode::SetLaser(1);
278 cout <<
"StiMaker::InitDetectors() -I- set laser time of flight correction" << endl;
281 if (IAttr(
"useSvt") && gStSvtDbMaker)
283 cout<<
"StiMaker::Init() -I- Adding detector group:SVT"<<endl;
289 if (IAttr(
"useSst") && gStSstDbMaker){
290 cout<<
"StiMaker::Init() -I- Adding detector group:Sst (ssd)"<<endl;
294 }
else if ( IAttr(
"useSsd") && gStSsdDbMaker){
295 cout<<
"StiMaker::Init() -I- Adding detector group:Ssd"<<endl;
301 if (IAttr(
"usePixel"))
303 cout<<
"StiMaker::Init() -I- Adding detector group:PIXEL"<<endl;
309 cout<<
"StiMaker::Init() -I- Adding detector group:Ist"<<endl;
317 Int_t StiMaker::InitRun(
int run)
320 cout <<
"StiMaker::InitRun() -I- Initialization Segment Started"<<endl;
324 masterBuilder->
build(*
this);
326 detectorContainer->initialize();
327 detectorContainer->
reset();
328 _seedFinder = _toolkit->getTrackSeedFinder();
330 _hitLoader = _toolkit->getHitLoader();
332 mMaxTimes = IAttr(
"setMaxTimes");
334 if (IAttr(
"useTracker")) {
340 TString seedFinders = SAttr(
"seedFinders");
343 if (seedFinders.Length()) {
345 TObjArray *sub_strings = seedFinders.Tokenize(
" .,");
347 for (
int i=0; i <= sub_strings->GetLast(); i++) {
349 TString &sub_string =
static_cast<TObjString*
>( sub_strings->At(i))->String();
350 if (sub_string[0]==
'!')
continue;
351 if ( !sub_string.CompareTo(
"CA", TString::kIgnoreCase) )
352 {n++;_tracker->addSeedFinder(_toolkit->getTrackSeedFinderCA());}
353 if ( !sub_string.CompareTo(
"Def", TString::kIgnoreCase) )
354 {n++;_tracker->addSeedFinder(_toolkit->getTrackSeedFinder());}
355 if ( !sub_string.CompareTo(
"KNN", TString::kIgnoreCase) )
356 {n++;_tracker->addSeedFinder(_toolkit->getTrackSeedFinderKNN());}
359 delete sub_strings;
break;
362 if (IAttr(
"StiCA")) {
363 _tracker->addSeedFinder(_toolkit->getTrackSeedFinderCA());
364 _tracker->addSeedFinder(_toolkit->getTrackSeedFinder());
368 _tracker->addSeedFinder(_toolkit->getTrackSeedFinder());
383 if (*SAttr(
"useTreeSearch")) _tracker->
setComb(IAttr(
"useTreeSearch"));
384 if ( IAttr(
"useTiming" )) _tracker->
setTiming();
390 if (IAttr(
"useEventFiller")) {
392 _eventFiller->setUseAux(IAttr(
"useAux"));
395 _trackContainer = _toolkit->getTrackContainer();
397 if (GetTopChain()->GetMakerInheritsFrom(
"StGenericVertexMaker")) {
398 _vertexFinder = _toolkit->getVertexFinder();
405 cout <<
"StiMaker::InitRun() -I- Initialization Segment Completed"<<endl;
408 return StMaker::InitRun(run);
414 cout <<
"StiMaker::Make() -I- Starting on new event"<<endl;
415 Int_t iAns=
kStOK,iAnz=0;
if (iAns){};
416 if (! _tracker)
return kStWarn;
417 StEvent *
event =
dynamic_cast<StEvent*
>( GetInputDS(
"StEvent") );
419 eventIsFinished =
false;
422 if (mTimg[kHitTimg]) mTimg[kHitTimg]->Start(0);
423 _hitLoader->loadEvent(event,_loaderTrackFilter,_loaderHitFilter);
424 if (mMaxTimes) _hitLoader->setMaxTimes(mMaxTimes);
425 if (mTimg[kHitTimg]) mTimg[kHitTimg]->Stop();
427 iAnz = MakeGlobalTracks(event);
428 if (iAnz) {MyClear();
return iAnz;}
432 iAnz = MakePrimaryTracks(event);
433 if (iAnz) {MyClear();
return iAnz;}
437 if (mPullTTree) {iAns = FillPulls();}
438 cout<<
"StiMaker::Make() -I- Done"<<endl;
440 if (iAnz)
return iAnz;
441 if (mTotPrimTks[1] && mTotPrimTks[0]>mTotPrimTks[1])
return kStStop;
447 Int_t StiMaker::MakeGlobalTracks(
StEvent * event) {
448 if (mTimg[kGloTimg]) mTimg[kGloTimg]->Start(0);
451 if (mMaxTimes>1) CleanGlobalTracks();
453 if (mTimg[kGloTimg]) mTimg[kGloTimg]->Stop();
454 if (mTimg[kFilTimg]) mTimg[kFilTimg]->Start(0);
456 _eventFiller->
fillEvent(event, _trackContainer);
457 if (mTimg[kFilTimg]) mTimg[kFilTimg]->Stop();
461 Int_t StiMaker::MakePrimaryTracks(
StEvent * event) {
462 if (! _vertexFinder)
return kStWarn;
463 if (mTimg[kVtxTimg]) mTimg[kVtxTimg]->Start(0);
464 _vertexFinder->
fit(event);
465 const std::vector<StiHit*> *vertexes = _vertexFinder->result();
466 if (mTimg[kVtxTimg]) mTimg[kVtxTimg]->Stop();
467 if (vertexes && vertexes->size()) {
469 for (
size_t i=0;i<vertexes->size();i++) {
470 StiHit *vtx=(*vertexes)[i];
472 memcpy(vtxErr,vtx->errMtx(),
sizeof(vtxErr));
473 if (vtxErr[0]>MIN_VTX_ERR2
474 && vtxErr[2]>MIN_VTX_ERR2
475 && vtxErr[5]>MIN_VTX_ERR2)
continue;
476 memset(vtxErr,0,
sizeof(vtxErr));
477 vtxErr[0]=MIN_VTX_ERR2;
478 vtxErr[2]=MIN_VTX_ERR2;
479 vtxErr[5]=MIN_VTX_ERR2;
482 if (mTimg[kPriTimg]) mTimg[kPriTimg]->Start(0);
484 _tracker->extendTracksToVertices(*vertexes);
485 mTotPrimTks[0]+=_tracker->getNPrims();
487 if (mTimg[kPriTimg]) mTimg[kPriTimg]->Stop();
490 if (mTimg[kFilTimg]) mTimg[kFilTimg]->Start(0);
491 if (_eventFiller) {_eventFiller->fillEventPrimaries(); }
492 if (mTimg[kFilTimg]) mTimg[kFilTimg]->Stop();
497 void StiMaker::MyClear()
501 _toolkit->getHitFactory()->
clear();
502 _toolkit->getTrackNodeFactory()->
clear();
503 _toolkit->getTrackNodeExtFactory()->
clear();
504 _toolkit->getTrackNodeInfFactory()->
clear();
505 _toolkit->getTrackFactory()->
clear();
513 Int_t StiMaker::InitPulls()
515 if (!IAttr(
"makePulls"))
return 0;
519 TFile *tfile = GetTFile();
521 TString ts = bfc->GetFileIn();
525 ts= gSystem->BaseName(ts);
526 int ext = ts.Index(
".");
527 if (ext>0) ts.Replace(ext,999,
"");
528 ts +=
".stipull.root";
529 tfile = mPullFile =
new TFile(ts,
"RECREATE",
"TTree Sti Pulls ROOT file");
532 mPullTTree =
new TTree(
"StiPulls",
"TTree Sti pulls");
533 mPullTTree->SetAutoSave(100000000);
535 TBranch *branch = mPullTTree->Branch(
"event", mPullEvent->ClassName(),&mPullEvent, 16000,99);
536 branch->SetAutoDelete(kFALSE);
537 _eventFiller->setPullEvent(mPullEvent);
541 Int_t StiMaker::FillPulls()
544 mPullEvent->mRun = hddr->GetRunNumber();
545 mPullEvent->mEvt = hddr->GetEventNumber();
546 mPullEvent->mDate = hddr->GetDateTime();
547 mPullEvent->mChi2 = 0;
549 memset(mPullEvent->mVtx,0,
sizeof(mPullEvent->mVtx));
550 memset(mPullEvent->mEtx,0,
sizeof(mPullEvent->mEtx));
554 mPullEvent->mVtx[0] = vertex->
x_g();
555 mPullEvent->mVtx[1] = vertex->y_g();
556 mPullEvent->mVtx[2] = vertex->z_g();
557 TCL::ucopy(vertex->errMtx(),mPullEvent->mEtx,6);
560 mPullEvent->Finish();
562 for (
int i=0; i<3; i++) {mPullHits[i]+=mPullEvent->mNHits[i];}
563 if (! IAttr(
".Privilege"))
return kStOK;
565 int k;
for (k=2; k>=0; k--) {
if (mPullHits[k])
break;}
566 if (k<0)
return kStOK;
567 k = mPullHits[k]<<(k*3);
572 TDataSet *StiMaker::FindDataSet (
const char* logInput,
const StMaker *uppMk,
575 TDataSet *ds = StMaker::FindDataSet(logInput,uppMk,dowMk);
577 if (ds || strcmp(logInput,
"STIGEOM"))
return ds;
584 TList *listOfVolume = gGeometry->GetListOfNodes();
587 listOfVolume->Remove(fVolume);
588 listOfVolume->Remove(fVolume);
591 ((
StiMaker *)
this)->AddConst(fVolume);
592 if (Debug()) fVolume->
ls(3);
599 int nA = a->getFitPointCount();
600 int nB = b->getFitPointCount();
601 if (nA!=nB)
return (nA > nB);
606 int StiMaker::CleanGlobalTracks()
608 for (
int iTk=0; iTk< (int)_trackContainer->size(); iTk++)
610 auto* kTrack =
static_cast<StiKalmanTrack*
>((*_trackContainer)[iTk]);
613 sort(_trackContainer->begin(), _trackContainer->end(),TrackCompareStatus );
615 for (
int iTk=0; iTk<(int) _trackContainer->size(); iTk++)
623 for (
auto nodeIt =kTrack->begin();nodeIt!=kTrack->end();nodeIt++)
626 if (node->isDca()) {dcaNode = node;
continue;}
627 StiHit *
hit = node->getHit();
if (!hit)
continue;
628 if (!node->isValid()) {node->setHit(0);
continue;}
629 if (node->getChi2()>1e2) {node->setHit(0);
continue;}
630 if (hit->
timesUsed()) {nNits++; node->setHit(0);}
634 if (!nNits)
continue;
635 if (nHits<5) { kTrack->setFlag(-1);
continue; }
636 if (dcaNode) kTrack->removeNode(dcaNode);
639 int ans = kTrack->refit();
640 if (ans || kTrack->getFitPointCount()<5)
641 { kTrack->setFlag(-1);
continue; }
645 StiTrackNode *extenDca = kTrack->extendToVertex(&dcaHit);
646 if (extenDca) kTrack->add(extenDca,kOutsideIn);
650 kTrack->reserveHits();
654 for (
int iTk=0; iTk< (int)_trackContainer->size(); iTk++)
656 auto* kTrack = ((*_trackContainer)[iTk]);
657 if (kTrack->getFlag()<0)
continue;
658 if (jTk!=iTk)(*_trackContainer)[jTk]=kTrack;
661 _trackContainer->resize(jTk);
663 for (
int iTk=0; iTk<(int) _trackContainer->size(); iTk++)
667 int nHit = 0,nNode = 0;
668 for (
auto nodeIt =kTrack->begin();nodeIt!=kTrack->end();nodeIt++)
672 StiHit *hit = node->getHit();
if (!hit)
continue;
676 assert(nHit || !nNode);
678 return _trackContainer->size();
681 void StiMaker::FinishTracks (
int gloPri)
698 int nTk=0,nNodes=0,nInside=0,nHits=0;
700 for (
int itk=0; itk<(int)tkV->size(); itk++)
703 if (gloPri && !track->
isPrimary())
continue;
707 nNodes=0;nInside=0;nHits=0;
708 for (;tNode!=eNode;++tNode)
711 if(!node->isValid())
continue;
712 if (node->isDca() )
continue;
713 StiHit *hit = node->getHit();
714 if (hit && !hit->
detector())
continue;
716 if ( hit && node->getChi2()<100) nHits++;
723 int qa,idt = track->idTruth(&qa);
if(idt){};
1205 for (
int itk=0; itk<(int)tkV->size(); itk++)
1210 for (;(node=it());it++){
1211 const StiHit *hit = node->getHit();
1214 assert(node->getChi2()<1000.);
virtual void initialize()
Initialize the finder.
virtual void initialize()
Initialize the finder.
void setError(const StMatrixF &)
virtual void findTracks()
Find all tracks of the currently loaded event.
Definition of Kalman Track.
void makeDca()
Make fake hit for dca calculation.
virtual double getChi2() const =0
Get chi2 of this track.
virtual int fit(StEvent *)=0
Find the vertex(es) associated with the given event.
Abstract definition of a Track.
virtual void Clear(Option_t *option="")
User defined functions.
virtual void reset()
Reset the tracker.
void reserveHits(int yes=1)
int getNTracks() const
get number of tracks
const StiDetector * detector() const
void setComb(int comb=7)
Set the vertex finder used by this tracker.
Float_t x_g() const
Return the global x, y, z values.
virtual void finish() const
Finish the tracker.
virtual void ls(Option_t *option="") const
void setTiming()
Set timing of tracking.
Definition of Kalman Track.
UInt_t timesUsed() const
Return the number of times this hit was assigned to a track.
const StiKTNBidirectionalIterator & end() const
void reset()
This performs a full internal reset of interator structure.
virtual void build(StMaker &source)
void fillEvent(StEvent *e, StiTrackContainer *t)
virtual void clear()=0
Clear/delete all objects owned by this factory.
virtual void clear()
Clear the tracker.
StiKTNBidirectionalIterator begin() const