00001
00002
00003
00004 #include "TFile.h"
00005 #include "StMessMgr.h"
00006
00007 #include "StiForwardTrackMaker.h"
00008 #include "StEvent.h"
00009 #include "StPrimaryVertex.h"
00010
00011 #include "Sti/StiToolkit.h"
00012 #include "Sti/StiKalmanTrack.h"
00013 #include "Sti/StiKalmanTrackNode.h"
00014 #include "StiMaker/StiMaker.h"
00015 #include "Sti/StiTrackContainer.h"
00016
00017 #include "Sti/StiHitContainer.h"
00018 #include "Sti/StiLocalTrackSeedFinder.h"
00019 #include "Sti/StiHit.h"
00020 #include "Sti/StiSortedHitIterator.h"
00021 #include "Sti/StiDetectorContainer.h"
00022 #include "Sti/StiKalmanTrackFinder.h"
00023
00024 #include "StDetectorId.h"
00025 #include "StHit.h"
00026 #include "TFile.h"
00027 #define xG(t) (t->x_g())
00028 #define yG(t) (t->y_g())
00029 #define zG(t) (t->z_g())
00030 #define rxyG(t) sqrt(xG(t)*xG(t) + yG(t)*yG(t))
00031 #define rG(t) sqrt(xG(t)*xG(t) + yG(t)*yG(t) + zG(t)*zG(t))
00032 #define xL(t) (t->getX())
00033 #define yL(t) (t->getY())
00034 #define zL(t) (t->getZ())
00035 #define ezL(t) sqrt(t->getCzz())
00036 #define eyL(t) sqrt(t->getCyy())
00037
00038
00039 ClassImp(StiForwardTrackMaker)
00040
00041
00042 StiForwardTrackMaker::StiForwardTrackMaker(const char *name):StMaker(name){
00043 mToolkit=0;
00044 mTotEve=0;
00045 mTotMatchedSeeds=0;
00046 mTotMatchedTracks=0;
00047 HList=0;
00048 memset(hA,0,sizeof(hA));
00049 mMaxTrkDcaRxy = 3.0;
00050 mMaxZdca = 4;
00051
00052 mMinEta = 0.9;
00053 mAllHits = 0;
00054 mForwardHits = 0;
00055 mTrackSeeds = 0;
00056 mSeedGenerator = 0;
00057 mTrackFinder = 0;
00058 }
00059
00060
00061
00062 StiForwardTrackMaker::~StiForwardTrackMaker(){
00063
00064 }
00065
00066
00067
00069 Int_t StiForwardTrackMaker::Init(){
00070
00071
00072 StiMaker* sti = (StiMaker*)StMaker::GetChain()->GetMaker("Sti");
00073 if(sti==0) {
00074 gMessMgr->Warning() <<GetName()<<"no STi Maker, it is fatal"<<endm;
00075 return kStErr;
00076 }
00077
00078
00079 mToolkit = sti->getToolkit();
00080 assert(mToolkit);
00081
00082
00083 mAllHits = mToolkit->getHitContainer();
00084 assert(mAllHits);
00085
00086
00087 mForwardHits = new StiHitContainer("mForwardHits","forward hits",mToolkit->getHitFactory());
00088
00089
00090 mTrackSeeds = new StiTrackContainer("mTrackSeeds","forward track seeds");
00091
00092
00093 mSeedGenerator = new StiLocalTrackSeedFinder("mSeedGenerator","builds track seeds",mToolkit->getTrackFactory(), mForwardHits,mToolkit->getDetectorContainer());
00094
00095
00096 mTrackFinder = new StiKalmanTrackFinder(mToolkit);
00097
00098
00099 HList=new TObjArray(0);
00100 initHisto();
00101 HList->ls();
00102
00103 gMessMgr->Info() << GetName()
00104 <<"::Cuts"
00105 <<"\n MaxTrkDcaRxy/cm = "<< mMaxTrkDcaRxy
00106 <<"\n mMaxZdca = "<< mMaxZdca
00107 <<"\n mMinEta = "<< mMinEta
00108 <<endm;
00109
00110 return StMaker::Init();
00111 }
00112
00113
00114
00116 Int_t StiForwardTrackMaker::Make(){
00117 return MakeAfterSti();
00118 }
00119
00120
00122 Int_t StiForwardTrackMaker::MakeInSti()
00123 {
00124 if(mToolkit==0) {
00125 gMessMgr->Warning()<<GetName()<<"no Sti tool kit "<<GetName()<<" is OFF"<<endm;
00126 return kStErr;
00127 }
00128 else if(mAllHits==0) {
00129 gMessMgr->Warning() <<"no Sti hits present: "<<GetName()<<" is OFF"<<endm;
00130 return kStErr;
00131 }
00132
00133
00134 int nV=vertL.size();
00135 StEvent *event = (StEvent *) GetInputDS("StEvent");
00136
00137 gMessMgr->Info() << "\n JJJ1 "<<GetName()<<":: MakeInSti(), eveID="<<event->id()<<" nVert="<<nV<<endm;
00138
00139
00140 int iv;
00141 for(iv=0;iv<nV;iv++) {
00142 VertexV V=vertL[iv];
00143 printf("iv=%d Vz=%.2f +/-%.2f \n",iv,V.z,V.ez );
00144 hA[1]->Fill(V.z);
00145 }
00146
00147 getForwardHits(mAllHits, mForwardHits, mToolkit->getDetectorContainer(), mMinEta);
00148 cout<<"We started with " << mAllHits->size() << " hits and ended with " << mForwardHits->size() << " in the forward region" << endl;
00149
00150 buildTrackSeeds(mForwardHits, mTrackSeeds, mSeedGenerator);
00151
00152
00153 extendTracks();
00154
00155
00156
00157 StiSortedHitIterator it = StiSortedHitIterator(mForwardHits, mToolkit->getDetectorContainer()->begin(), mToolkit->getDetectorContainer()->end());
00158 StiHit* hit = 0;
00159 float phi;
00160 while(it!=StiSortedHitIterator())
00161 {
00162 hit = &(*it);
00163
00164
00165 hA[2]->Fill( -log( rxyG(hit)/(zG(hit)+rG(hit)) ) );
00166
00167
00168 phi = atan(yG(hit)/xG(hit));
00169 if(xG(hit)<0 && yG(hit)<0) phi = phi - 3.14;
00170 else if(xG(hit)<0) phi = phi + 3.14;
00171 hA[3]->Fill(phi);
00172
00173 it++;
00174 }
00175
00176
00177
00178 StiTrackContainer* tracks = mToolkit->getTrackContainer();
00179 if(tracks==0) {
00180 gMessMgr->Warning() <<"no STi tracks , skip eve"<<endm;
00181 return kStErr ;
00182 }
00183
00184 cout<<"There are "<<tracks->getTrackCount(0)<<" original tracks and "<<mTrackSeeds->getTrackCount(0)<<" forward track seeds"<<endl;
00185
00186 matchVertex(tracks,vertL,mMaxZdca,nV,hA[9],mTotMatchedTracks);
00187
00188 matchVertex(mTrackSeeds,vertL,mMaxZdca,nV,hA[8],mTotMatchedSeeds);
00189
00190 return kStOK;
00191 }
00192
00193
00195 Int_t StiForwardTrackMaker::MakeAfterSti(){
00196
00197 StEvent *event = (StEvent *) GetInputDS("StEvent");
00198 assert(event);
00199 eveID=event->id();
00200 mTotEve++;
00201 int nV=event->numberOfPrimaryVertices();
00202
00203 gMessMgr->Info() << "\n JJJ2 "<<GetName()<<"MakeAfterSti(), START nEve="<<mTotEve<<" eveID="<<eveID<< " nPrimVertex="<<nV<< endm;
00204
00205 hA[0]->Fill(nV);
00206
00207 if(nV<=0) {
00208 gMessMgr->Info() << GetName()<<" event dropped, no vertex found"<<endm;
00209 return kStOK;
00210 }
00211
00212
00213 return kStOK;
00214 }
00215
00216
00217
00218 void
00219 StiForwardTrackMaker::Clear(const char* opt){
00220 gMessMgr->Info() <<GetName()<<"::Clear()"<< endm;
00221 eveID=0;
00222 vertL.clear();
00223 mForwardHits->clear();
00224 mTrackSeeds->clear();
00225 mSeedGenerator->reset();
00226 }
00227
00228
00229
00230 void
00231 StiForwardTrackMaker::initHisto() {
00232 assert(HList);
00233 hA[0]=new TH1F("nV","No. of vertices per eve",20,-0.5,19.5);
00234 hA[1]=new TH1F("zV","reconstructed vertices (any); Z (cm)",200,-200,200);
00235
00236 hA[2] = new TH1F("etaNotUsed","eta of unused forward hits",20,0.8,2.1);
00237 hA[3] = new TH1F("phiNotUsed","phi of unused forward hits",20,-3.14,3.14);
00238 hA[4] = new TH1F("etaUsed","eta of hits used by previous tracker",20,0.8,2.1);
00239 hA[5] = new TH1F("phiUsed","phi of hits used by previous tracker",20,-3.14,3.14);
00240 hA[6] = new TH1F("seedHits","number of seed hits used for each track",20,1,20);
00241 hA[7] = new TH1F("trackHits1","total # of hits/track after inward Kalman",20,1,20);
00242 hA[10] = new TH1F("trackHits2","total # of hits/track after outward Kalman",20,1,20);
00243 hA[8] = new TH1F("deltaZkalman","zDCA-zVertex for tracks after Kalman",200,-200,200);
00244 hA[9] = new TH1F("deltaZtracks","zDCA-zVertex for old tracks",200,-200,200);
00245
00246 int i;
00247 for(i=0;i<mxHA; i++) if(hA[i]) HList->Add(hA[i]);
00248 }
00249
00250
00251
00252 void
00253 StiForwardTrackMaker::saveHisto(TString fname){
00254 TString outName=fname+".hist.root";
00255 TFile f( outName,"recreate");
00256 assert(f.IsOpen());
00257 printf("%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
00258 HList->ls();
00259 HList->Write();
00260 f.Close();
00261 }
00262
00263
00264
00265 Int_t
00266 StiForwardTrackMaker::Finish(){
00267 saveHisto(GetName());
00268 cout<<"Total matched track seeds: "<<mTotMatchedSeeds<<" and total matched tracks: "<<mTotMatchedTracks<<endl;
00269 return kStOK;
00270 }
00271
00272
00273
00274
00275 void StiForwardTrackMaker::getForwardHits(StiHitContainer* allHits, StiHitContainer* forwardHits, StiDetectorContainer* detector, double minEta)
00276 {
00277 StiSortedHitIterator it = StiSortedHitIterator(allHits, detector->begin(), detector->end());
00278 StiHit* hit = 0;
00279
00280 while(it!=StiSortedHitIterator())
00281 {
00282 hit = &(*it);
00283 StDetectorId id = (static_cast <const StHit*>(hit->stHit()))->detector();
00284 if( rxyG(hit)/(zG(hit)+rG(hit)) < exp(-minEta) && id==kTpcId)
00285 {
00286 if(hit->timesUsed()==0)forwardHits->add(hit);
00287 else
00288 {
00289 hA[4]->Fill( -log( rxyG(hit)/(zG(hit)+rG(hit)) ) );
00290
00291
00292 float phi = atan(yG(hit)/xG(hit));
00293 if(xG(hit)<0 && yG(hit)<0) phi = phi - 3.14;
00294 else if(xG(hit)<0) phi = phi + 3.14;
00295 hA[5]->Fill(phi);
00296 }
00297 }
00298 it++;
00299 }
00300
00301 forwardHits->sortHits();
00302 }
00303
00304
00305 void StiForwardTrackMaker::buildTrackSeeds(const StiHitContainer* forwardHits, StiTrackContainer* trackSeeds, StiLocalTrackSeedFinder* seedGenerator)
00306 {
00307 StiTrack* track = seedGenerator->findTrack();
00308
00309 while(track != 0)
00310 {
00311 hA[6]->Fill(track->getPointCount());
00312 trackSeeds->add(track);
00313 track = seedGenerator->findTrack();
00314 }
00315 }
00316
00317 void StiForwardTrackMaker::extendTracks()
00318 {
00319 mTrackFinder->initialize();
00320
00321
00322 float zDCA, ezDCA, RxyDCA;
00323
00324
00325 for(StiTrackContainer::const_iterator it=mTrackSeeds->begin(); it!=mTrackSeeds->end(); it++)
00326 {
00327 while(mTrackFinder->find(*it,0,2)){};
00328 hA[7]->Fill((*it)->getPointCount());
00329 while(mTrackFinder->find(*it,1,0)){};
00330 hA[10]->Fill((*it)->getPointCount());
00331
00332 if(examineTrackDca(static_cast<StiKalmanTrack*>(*it), zDCA, ezDCA, RxyDCA)){
00333
00334 cout << "This track passed the cut "<<**it<<endl;
00335 }
00336 }
00337
00338
00339 }
00340
00341
00342
00343
00344 void StiForwardTrackMaker::matchVertex(StiTrackContainer* tracks, vector <VertexV> &vertL, double &mMaxZdca, int &nV, TH1* h, int &totalMatched)
00345 {
00346 int nAll=0, nAny=0, nTry=0, nAcc=0;
00347 for (StiTrackContainer::const_iterator it=(*tracks).begin(); it!=(*tracks).end(); ++it) {
00348 const StiKalmanTrack* track = static_cast<StiKalmanTrack*>(*it);
00349 nAll++;
00350 if(track->getFlag()!=true) nAny++;
00351
00352
00353
00354
00355 float zDca, ezDca, rxyDca;
00356 if(!examineTrackDca(track, zDca, ezDca, rxyDca)) continue;
00357 nTry++;
00358
00359
00360
00361 for(int iv=0;iv<nV;iv++) {
00362 VertexV V=vertL[iv];
00363 h->Fill(zDca-V.z);
00364 if( fabs(zDca-V.z) > mMaxZdca )continue;
00365 nAcc++;
00366
00367 break;
00368 }
00369 }
00370
00371 gMessMgr->Info() << "\n"<<GetName()<<" We have "<<nAll<<" tracks, found "<<nAny<<" flagged tracks, try ZDca for "<<nTry<<", match to vertex:"<<nAcc<<"\n"<<endm;
00372 totalMatched = nAcc + totalMatched;
00373 }
00374
00375 bool
00376 StiForwardTrackMaker::examineTrackDca(const StiKalmanTrack*track,
00377 float &zDca, float &ezDca, float &rxyDca){
00378
00379
00380
00381
00382 StiKalmanTrack track1=*track;
00383 StiKalmanTrackNode* bmNode=track1.extrapolateToBeam();
00384 if(bmNode==0) {
00385
00386 return false ;
00387 }
00388
00389 float rxy=rxyG(bmNode);
00390
00391 if(rxy>mMaxTrkDcaRxy) return false;
00392
00393
00394
00395 zDca=zG(bmNode);
00396 ezDca=ezL(bmNode);
00397 rxyDca=rxy;
00398
00399 return true;
00400 }
00401
00402
00403
00404 void
00405 StiForwardTrackMaker::addVertex(float z, float ez){
00406 VertexV V;
00407 V.z=z;
00408 V.ez=ez;
00409 vertL.push_back(V);
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450