00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
#include "RVersion.h"
00418
#if ROOT_VERSION_CODE < 331013
00419
#include "TCL.h"
00420
#else
00421
#include "TCernLib.h"
00422
#endif
00423
00424
#include "Stiostream.h"
00425
#include <algorithm>
00426
#include <stdexcept>
00427
using namespace std;
00428
00429
00430
#include "StPhysicalHelix.hh"
00431
#include "StThreeVector.hh"
00432
#include "StThreeVectorF.hh"
00433
#include "PhysicalConstants.h"
00434
#include "SystemOfUnits.h"
00435
#include "StTrackDefinitions.h"
00436
#include "StTrackMethod.h"
00437
#include "StDedxMethod.h"
00438
00439
00440
#include "StPrimaryVertex.h"
00441
#include "StEventTypes.h"
00442
#include "StDetectorId.h"
00443
#include "StHelix.hh"
00444
#include "StDcaGeometry.h"
00445
#include "StHit.h"
00446
00447
00448
#include "StEventUtilities/StEventHelper.h"
00449
#include "StEventUtilities/StuFixTopoMap.cxx"
00450
00451
#include "Sti/StiTrackContainer.h"
00452
#include "Sti/StiKalmanTrack.h"
00453
#include "Sti/StiKalmanTrackFitterParameters.h"
00455
#include "StiUtilities/StiDebug.h"
00456
#include "StiUtilities/StiPullEvent.h"
00457
00458
00459
#include "StiMaker/StiStEventFiller.h"
00460
00461
#include "TMath.h"
00462
#define NICE(angle) StiKalmanTrackNode::nice((angle))
00463
00464
00465 StiStEventFiller::StiStEventFiller() : mEvent(0), mTrackStore(0), mTrkNodeMap()
00466 {
00467 mUseAux = 0;
00468 mAux = 0;
00469 mGloPri = 0;
00470 mPullEvent=0;
00471
00472 originD =
new StThreeVectorD(0,0,0);
00473 physicalHelix =
new StPhysicalHelixD(0.,0.,0.,*originD,-1);
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
unsigned short bit = 1 << tpcOther;
00490 mStiEncoded = kITKalmanFitId + bit;
00491
00492 }
00493
00494
00495 StiStEventFiller::~StiStEventFiller()
00496 {
00497
delete physicalHelix; physicalHelix=0;
00498
delete originD; originD =0;
00499 cout <<
"StiStEventFiller::~StiStEventFiller()"<<endl;
00500 }
00501
00502
00503
00504
struct StreamStHit
00505 {
00506
void operator()(
const StHit* h)
00507 {
00508
00509
if (
const StTpcHit* hit = dynamic_cast<const StTpcHit*>(h))
00510 {
00511 cout <<hit->position() <<
" Sector: " << hit->sector() <<
" Padrow: " << hit->padrow() << endl;
00512 }
00513
else if (
const StSvtHit* hit = dynamic_cast<const StSvtHit*>(h))
00514 {
00515 cout << hit->position() <<
" layer: " << hit->layer() <<
" ladder: " << hit->ladder()
00516 <<
" wafer: " << hit->wafer() <<
" barrel: " << hit->barrel() << endl;
00517 }
00518
else
00519 {
00520 cout << hit->position() << endl;
00521 }
00522 }
00523 };
00524
00525
00577
00578 void StiStEventFiller::fillEvent(
StEvent* e,
StiTrackContainer* t)
00579 {
00580
00581 mGloPri=0;
00582
if (e==0 || t==0)
00583 {
00584 cout <<
"StiStEventFiller::fillEvent(). ERROR:\t"
00585 <<
"Null StEvent ("<<e<<
") || StiTrackContainer ("<<t<<
"). Exit"<<endl;
00586
return;
00587 }
00588 mEvent = e;
00589
if (mUseAux) { mAux =
new StiAux; e->Add(mAux);}
00590 mTrackStore = t;
00591 mTrkNodeMap.clear();
00592 StSPtrVecTrackNode& trNodeVec = mEvent->
trackNodes();
00593 StSPtrVecTrackDetectorInfo& detInfoVec = mEvent->
trackDetectorInfo();
00594
int errorCount=0;
00595
00596
int fillTrackCount1=0;
00597
int fillTrackCount2=0;
00598
int fillTrackCountG=0;
00599 StErrorHelper errh;
00600 mTrackNumber=0;
00601
for (vector<StiTrack*>::iterator trackIt = mTrackStore->begin(); trackIt!=mTrackStore->end();++trackIt)
00602 {
00603
StiKalmanTrack* kTrack = static_cast<StiKalmanTrack*>(*trackIt);
00604
if (!accept(kTrack))
continue;
00605 mTrackNumber++;
00606
StTrackDetectorInfo* detInfo =
new StTrackDetectorInfo;
00607
fillDetectorInfo(detInfo,kTrack,
true);
00608
00609
StTrackNode* trackNode =
new StTrackNode;
00610
00611
StGlobalTrack* gTrack =
new StGlobalTrack;
00612
try
00613 {
00614 fillTrackCount1++;
00615 fillTrack(gTrack,kTrack,detInfo);
00616
00617 detInfoVec.push_back(detInfo);
00618
00619 gTrack->
setKey((
unsigned short)kTrack->
getId());
00620 trackNode->
addTrack(gTrack);
00621 trNodeVec.push_back(trackNode);
00622
00623
00624
00625
00626
00627 mTrkNodeMap.insert(map<StiKalmanTrack*,StTrackNode*>::value_type (kTrack,trNodeVec.back()) );
00628
if (trackNode->
entries(global)<1)
00629 cout <<
"StiStEventFiller::fillEvent() -E- Track Node has no entries!! -------------------------" << endl;
00630
int ibad = gTrack->
bad();
00631 errh.Add(ibad);
00632
if (ibad) {
00633
00634
00635 }
00636 fillTrackCount2++;
00637 fillPulls(kTrack,0);
00638
if (gTrack->
numberOfPossiblePoints()<10)
continue;
00639
if (gTrack->
geometry()->
momentum().mag()<0.1)
continue;
00640 fillTrackCountG++;
00641
00642 }
00643
catch (runtime_error & rte )
00644 {
00645 cout <<
"StiStEventFiller::fillEvent() -W- runtime-e filling track"<<rte.what() << endl;
00646
delete trackNode;
00647
delete detInfo;
00648
delete gTrack;
00649 }
00650
catch (...)
00651 {
00652 cout <<
"StiStEventFiller::fillEvent() -W- Unknown exception filling track."<<endl;
00653
delete trackNode;
00654
delete detInfo;
00655
delete gTrack;
00656 }
00657 }
00658
if (errorCount>4)
00659 cout <<
"There were "<<errorCount<<
"runtime_error while filling StEvent"<<endl;
00660
00661 cout <<
"StiStEventFiller::fillEvent() -I- Number of filled as global(1):"<< fillTrackCount1<<endl;
00662 cout <<
"StiStEventFiller::fillEvent() -I- Number of filled as global(2):"<< fillTrackCount2<<endl;
00663 cout <<
"StiStEventFiller::fillEvent() -I- Number of filled GOOD globals:"<< fillTrackCountG<<endl;
00664 errh.Print();
00665
00666
return;
00667 }
00668
00669
void StiStEventFiller::fillEventPrimaries()
00670 {
00671
00672 mGloPri=1;
00673
if (!mTrkNodeMap.size())
00674 {
00675 cout <<
"StiStEventFiller::fillEventPrimaries(). ERROR:\t"
00676 <<
"Mapping between the StTrackNodes and the StiKalmanTracks is empty. Exit." << endl;
00677
return;
00678 }
00679
00680
StPrimaryVertex* vertex = 0;
00681 StSPtrVecTrackDetectorInfo& detInfoVec = mEvent->
trackDetectorInfo();
00682 cout <<
"StiStEventFiller::fillEventPrimaries() -I- Tracks in container:" << mTrackStore->size() << endl;
00683
int mTrackN=0,mVertN=0;
00684
int noPipe=0;
00685
int ifcOK=0;
00686
int fillTrackCount1=0;
00687
int fillTrackCount2=0;
00688
int fillTrackCountG=0;
00689 StErrorHelper errh;
00690
int nTracks = mTrackStore->size();
00691
StiKalmanTrack *kTrack = 0;
00692
StPrimaryTrack *pTrack = 0;
00693
StGlobalTrack *gTrack = 0;
00694
StTrackNode *nTRack = 0;
00695 mTrackNumber=0;
00696
for (mTrackN=0; mTrackN<nTracks;++mTrackN) {
00697 kTrack = (
StiKalmanTrack*)(*mTrackStore)[mTrackN];
00698
if (!accept(kTrack))
continue;
00699 map<StiKalmanTrack*, StTrackNode*>::iterator itKtrack = mTrkNodeMap.find(kTrack);
00700
if (itKtrack == mTrkNodeMap.end())
continue;
00701 mTrackNumber++;
00702
00703 nTRack = (*itKtrack).second;
00704 assert(nTRack->
entries()<=10);
00705 assert(nTRack->
entries(global));
00706
00707
00708
00709
00710
00711
00712 gTrack = static_cast<StGlobalTrack*>(nTRack->
track(global));
00713 assert(gTrack->
key()==kTrack->
getId());
00714
float minDca = 1e10;
00715
00716 pTrack = 0;
00717
for (mVertN=0; (vertex = mEvent->
primaryVertex(mVertN));mVertN++) {
00718 StThreeVectorD vertexPosition = vertex->position();
00719
double zPrim = vertexPosition.z();
00720
00721
float globalDca = impactParameter(gTrack,vertexPosition);
00722
if (fabs(minDca) > fabs(globalDca)) minDca = globalDca;
00723
00724
if (!kTrack->
isPrimary())
continue;
00725
StiKalmanTrackNode *lastNode = kTrack->
getLastNode();
00726
StiHit *pHit = lastNode->getHit();
00727
if (fabs(pHit->
z_g()-zPrim)>0.1)
continue;
00728
00729 fillTrackCount1++;
00730
00731
StTrackDetectorInfo* detInfo =
new StTrackDetectorInfo;
00732
fillDetectorInfo(detInfo,kTrack,
false);
00733 fillPulls(kTrack,1);
00734
StPrimaryTrack* pTrack =
new StPrimaryTrack;
00735 pTrack->
setKey( gTrack->
key());
00736
00737 fillTrack(pTrack,kTrack, detInfo);
00738
00739 detInfoVec.push_back(detInfo);
00740
00741 nTRack->
addTrack(pTrack);
00742 vertex->addDaughter(pTrack);
00743 fillTrackCount2++;
00744
int ibad = pTrack->
bad();
00745 errh.Add(ibad);
00746
if (ibad) {
00747
00748
00749 }
00750
if (pTrack->
numberOfPossiblePoints()<10)
break;
00751
if (pTrack->
geometry()->
momentum().mag()<0.1)
break;
00752 fillTrackCountG++;
00753
break;
00754 }
00755 kTrack->
setDca(minDca);
00756 gTrack->
setImpactParameter(minDca);
00757
if (pTrack) pTrack->
setImpactParameter(minDca);
00758
00759 }
00760 mTrkNodeMap.clear();
00761 cout <<
"StiStEventFiller::fillEventPrimaries() -I- Primaries (1):"<< fillTrackCount1<<
" (2):"<< fillTrackCount2<<
" no pipe node:"<<noPipe<<
" with IFC:"<< ifcOK<<endl;
00762 cout <<
"StiStEventFiller::fillEventPrimaries() -I- GOOD:"<< fillTrackCountG <<endl;
00763 errh.Print();
00764
return;
00765 }
00766
00771
00772 void StiStEventFiller::fillDetectorInfo(
StTrackDetectorInfo* detInfo,
StiKalmanTrack* track,
bool refCountIncr)
00773 {
00774
00775
int dets[kMaxDetectorId][3];
00776 track->getAllPointCount(dets,kMaxDetectorId-1);
00777
for (
int i=1;i<kMaxDetectorId;i++) {
00778
if (!dets[i][1])
continue;
00779 detInfo->
setNumberOfPoints(dets[i][1],static_cast<StDetectorId>(i));
00780 }
00781
StiKTNIterator tNode = track->rbegin();
00782
StiKTNIterator eNode = track->rend();
00783
StiKalmanTrackNode *lastNode=0,*fistNode=0;
00784
for (;tNode!=eNode;++tNode)
00785 {
00786
StiKalmanTrackNode *node = &(*tNode);
00787
if(!node->isValid())
continue;
00788
00789
StiHit *stiHit = node->getHit();
00790
if (!stiHit)
continue;
00791
00792
if (node->getChi2()>1000)
continue;
00793
if (!node->isFitted())
continue;
00794
00795
const StiDetector *detector = node->getDetector();
00796 assert(detector == stiHit->
detector());
00797 assert(!detector || stiHit->
timesUsed());
00798
if (!fistNode) fistNode = node;
00799 lastNode = node;
00800
StHit *hh = (
StHit*)stiHit->
stHit();
00801
00802 FillStHitErr(hh,node);
00803
if (!detector)
continue;
00804
if (!hh)
continue;
00805 assert(detector->getGroupId()==hh->detector());
00806
00807 detInfo->
addHit(hh,refCountIncr);
00808
if (!refCountIncr)
continue;
00809 hh->setFitFlag(1);
00810
00811 fillResHack(hh,stiHit,node);
00812 }
00813 assert(lastNode && fistNode && (lastNode != fistNode));
00814
00815 StThreeVectorF posL(lastNode->
x_g(),lastNode->
y_g(),lastNode->
z_g());
00816 detInfo->
setLastPoint (posL);
00817 StThreeVectorF posF(fistNode->x_g(),fistNode->y_g(),fistNode->z_g());
00818 detInfo->
setFirstPoint(posF);
00819
00820
00821
00822 }
00823
00824
00825
void StiStEventFiller::fillGeometry(
StTrack* gTrack,
StiKalmanTrack* track,
bool outer)
00826 {
00827
00828 assert(gTrack);
00829 assert(track) ;
00830
00831
StiKalmanTrackNode* node = track->getInnOutMostNode(outer,3);
00832
StiHit *ihit = node->getHit();
00833 StThreeVectorF origin(node->
x_g(),node->
y_g(),node->
z_g());
00834 StThreeVectorF hitpos(ihit->
x_g(),ihit->
y_g(),ihit->
z_g());
00835
00836
double dif = (hitpos-origin).mag();
00837
00838
if (dif>3.) {
00839 dif = node->
z_g()-ihit->
z_g();
00840
double nowChi2 = node->
evaluateChi2(ihit);
00841 printf(
"***Track(%d) DIFF TOO BIG %g chi2 = %g %g\n",track->getId(),dif,node->getChi2(),nowChi2);
00842 printf(
"H=%g %g %g N =%g %g %g\n",ihit->
x() ,ihit->
y() ,ihit->
z()
00843 ,node->
getX(),node->
getY(),node->
getZ());
00844
const StMeasuredPoint *mp = ihit->
stHit();
00845 printf(
"H=%g %g %g N =%g %g %g\n",mp->
position().x(),mp->
position().y(),mp->
position().z()
00846 ,origin.x(),origin.y(),origin.z());
00847
00848 assert(fabs(dif)<50.);
00849 }
00850
00851
00852
00853
00854
int ibad = origin.bad();
00855
if (ibad) {
00856 cout <<
"StiStEventFiller::fillGeometry() Encountered non-finite numbers!!!! Bail out completely!!! " << endl;
00857 cout <<
"StThreeVectorF::bad() = " << ibad << endl;
00858 cout <<
"Last node had:" << endl;
00859 cout <<
"Ref Position " << node->getRefPosition() << endl;
00860 cout <<
"node->getY() " << node->
getY() << endl;
00861 cout <<
"node->getZ() " << node->
getZ() << endl;
00862 cout <<
"Ref Angle " << node->
getAlpha() << endl;
00863 cout <<
"origin " << origin << endl;
00864 cout <<
"curvature " << node->
getCurvature() << endl;
00865 abort();
00866 }
00867
StTrackGeometry* geometry =
new StHelixModel(
short(track->getCharge()),
00868 node->
getPsi(),
00869 fabs(node->
getCurvature()),
00870 node->
getDipAngle(),
00871 origin,
00872 node->
getGlobalMomentumF(),
00873 node->
getHelicity());
00874
00875
if (outer)
00876 gTrack->
setOuterGeometry(geometry);
00877
else
00878 gTrack->
setGeometry(geometry);
00879
00880
00881
return;
00882 }
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
void StiStEventFiller::fillFitTraits(
StTrack* gTrack,
StiKalmanTrack* track){
00898
00899
00900
unsigned short geantIdPidHyp = 9999;
00901
00902 geantIdPidHyp = 9;
00903
00904
00905
StiKalmanTrackNode* node = track->getInnerMostHitNode(3);
00906
float x[6],covMFloat[15];
00907 node->
getGlobalTpt(x,covMFloat);
00908
float chi2[2];
00909
00910 chi2[0] = track->getChi2();
00911 chi2[1] = -999;
00912
00913
00914
if (gTrack->
type()==primary) {
00915 assert(node->getDetector()==0);
00916 chi2[1]=node->getChi2();
00917 }
00918
00919
00920
00921
00922
StTrackFitTraits fitTraits(geantIdPidHyp,0,chi2,covMFloat);
00923
00924
00925
00926
int dets[kMaxDetectorId][3];
00927 track->getAllPointCount(dets,kMaxDetectorId-1);
00928
00929
for (
int i=1;i<kMaxDetectorId;i++) {
00930
if (!dets[i][2])
continue;
00931 fitTraits.
setNumberOfFitPoints((
unsigned char)dets[i][2],(StDetectorId)i);
00932 }
00933
if (gTrack->
type()==primary) {
00934 fitTraits.
setPrimaryVertexUsedInFit(
true);
00935 }
00936 gTrack->
setFitTraits(fitTraits);
00937
return;
00938 }
00939
00971
00972 void StiStEventFiller::fillFlags(
StTrack* gTrack) {
00973
if (gTrack->
type()==global) {
00974 gTrack->
setFlag(101);
00975 }
00976
else if (gTrack->
type()==primary) {
00977 gTrack->
setFlag(301);
00978 }
00979
StTrackFitTraits& fitTrait = gTrack->
fitTraits();
00980
00981
int svtFitPoints = fitTrait.
numberOfFitPoints(kSvtId);
00982
int ssdFitPoints = fitTrait.
numberOfFitPoints(kSsdId);
00983
int pxlFitPoints = fitTrait.
numberOfFitPoints(kPxlId);
00984
int istFitPoints = fitTrait.
numberOfFitPoints(kIstId);
00985
00989
00990
00991
00992
00993
00994
00995
if (svtFitPoints+ssdFitPoints+pxlFitPoints+istFitPoints>0) {
00996
if (gTrack->
type()==global) {
00997 gTrack->
setFlag(501);
00998 }
00999
else if (gTrack->
type()==primary) {
01000 gTrack->
setFlag(601);
01001 }
01002 }
01003
const StTrackDetectorInfo *dinfo = gTrack->
detectorInfo();
01004
if (dinfo) {
01005 Int_t NoTpcFitPoints = dinfo->
numberOfPoints(kTpcId);
01006 Int_t NoFtpcWestId = dinfo->
numberOfPoints(kFtpcWestId);
01007 Int_t NoFtpcEastId = dinfo->
numberOfPoints(kFtpcEastId);
01008
01009
01010 Int_t flag = TMath::Abs(gTrack->
flag());
01011
if (NoTpcFitPoints >= 11) {
01012
const StTrackDetectorInfo *dinfo = gTrack->
detectorInfo();
01013
const StPtrVecHit& hits = dinfo->
hits(kTpcId);
01014 Int_t Nhits = hits.size();
01015 Int_t NoWrongSignZ = 0;
01016
for (Int_t i = 0; i < Nhits; i++) {
01017
const StTpcHit *hit = (
StTpcHit *) hits[i];
01018
if (hit->position().z() < -1.0 && hit->sector() <= 12 ||
01019 hit->position().z() > 1.0 && hit->sector() > 12) NoWrongSignZ++;
01020 }
01021
if (NoWrongSignZ >= 2)
01022 gTrack->
setFlag((flag%1000) + 1000);
01023 }
01024
if (NoTpcFitPoints < 11 && NoFtpcWestId < 5 && NoFtpcEastId < 5) {
01025
01026
01027 gTrack->
setFlag(-(((flag/100)*100)+2));
01028
if (gTrack->
geometry()) {
01029
const StThreeVectorF &momentum = gTrack->
geometry()->
momentum();
01030
if (momentum.pseudoRapidity() > 0.5) {
01031
const StTrackDetectorInfo *dinfo = gTrack->
detectorInfo();
01032
const StPtrVecHit& hits = dinfo->
hits();
01033 Int_t Nhits = hits.size();
01034
for (Int_t i = 0; i < Nhits; i++) {
01035
const StHit *hit = hits[i];
01036
if (hit->position().z() > 150.0) {
01037 gTrack->
setFlag((((flag/100)*100)+11));
01038
return;
01039 }
01040 }
01041 }
01042 }
01043 }
01044 }
01045 }
01046
01047
void StiStEventFiller::fillTrack(
StTrack* gTrack,
StiKalmanTrack* track,
StTrackDetectorInfo* detInfo )
01048 {
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 gTrack->
setEncodedMethod(mStiEncoded);
01066
double tlen = track->getTrackLength();
01067 assert(tlen >0.0 && tlen<1000.);
01068 gTrack->
setLength(tlen);
01069
01070
01071
01072
01073
int dets[kMaxDetectorId][3];
01074 track->getAllPointCount(dets,kMaxDetectorId-1);
01075
for (
int i=1;i<kMaxDetectorId;i++) {
01076
if(!dets[i][0])
continue;
01077 gTrack->
setNumberOfPossiblePoints((
unsigned char)dets[i][0],(StDetectorId)i);
01078 }
01079
01080 fillGeometry(gTrack, track,
false);
01081 fillGeometry(gTrack, track,
true );
01082 fillFitTraits(gTrack, track);
01083 gTrack->
setDetectorInfo(detInfo);
01084 StuFixTopoMap(gTrack);
01085
fillFlags(gTrack);
01086
if (!track->isPrimary()) fillDca(gTrack,track);
01087
return;
01088 }
01089
01090
bool StiStEventFiller::accept(
StiKalmanTrack* track)
01091 {
01092
01093
01094
int nFittedPoints = track->getFitPointCount(0);
01095
if (nFittedPoints < 5 )
return 0;
01096
#if 0
01097
if (nFittedPoints < 10 && nFittedPoints*2 < nPossiblePoints)
return 0;
01098
if(track->getPt()<=0.1)
return 0;
01099
#endif
01100
if(track->getTrackLength()<=0)
return 0;
01101
01102
01103
01104
return 1;
01105 }
01106
01107
double StiStEventFiller::impactParameter(
StiKalmanTrack* track
01108 ,StThreeVectorD &vertexPosition)
01109 {
01110
StiKalmanTrackNode* node;
01111
01112 node = track->getInnerMostNode(2);
01113
01114
01115 originD->setX(node->
x_g());
01116 originD->setY(node->
y_g());
01117 originD->setZ(node->
z_g());
01118
01119
01120 physicalHelix->setParameters(fabs(node->
getCurvature()),
01121 node->
getDipAngle(),
01122 node->
getPhase(),
01123 *originD,
01124 node->
getHelicity());
01125
01126
01127
01128
return physicalHelix->distance(vertexPosition);
01129 }
01130
01131
double StiStEventFiller::impactParameter(
StTrack* track, StThreeVectorD &vertex)
01132 {
01133 StPhysicalHelixD helix = track->geometry()->helix();
01134
01135
01136
return helix.distance(vertex);
01137 }
01138
01139
void StiStEventFiller::fillResHack(
StHit *hh,
const StiHit *stiHit,
const StiKalmanTrackNode *node)
01140 {
01141
01142
if (!mAux)
return;
01143 StiAux_t aux;
01144
01145 aux.xnl[0] = node->
getX();
01146 aux.xnl[1] = node->
getY();
01147 aux.xnl[2] = node->
getZ();
01148
01149 aux.xhl[0] = stiHit->
x();
01150 aux.xhl[1] = stiHit->
y();
01151 aux.xhl[2] = stiHit->
z();
01152
01153 aux.ca = node->
getEta();
01154 aux.rho = node->
getCurvature();
01155 aux.nYY = node->
getCyy();
01156 aux.nZZ = node->
getCzz();
01157 aux.hYY = node->
getEyy();
01158 aux.hZZ = node->
getEzz();
01159
01160 aux.unl[0] = node->
getX();
01161 aux.unl[1] = node->
unTouched().mPar[0];
01162 aux.unl[2] = node->
unTouched().mPar[1];
01163 aux.uYY = sqrt(node->
unTouched().mErr[0]);
01164 aux.uZZ = sqrt(node->
unTouched().mErr[2]);
01165
01166
01167
01168 aux.xng[0] = node->
x_g();
01169 aux.xng[1] = node->
y_g();
01170 aux.xng[2] = node->
z_g();
01171
01172 aux.xhg[0] = stiHit->
x_g();
01173 aux.xhg[1] = stiHit->
y_g();
01174 aux.xhg[2] = stiHit->
z_g();
01175 aux.psi = node->
getPsi();
01176 aux.dip = node->
getDipAngle();
01177
01178
double chi2 = node->getChi2();
if (chi2>1000) chi2=1000;
01179 aux.chi2 = chi2;
01180
int id = mAux->AddIt(&aux);
01181 assert(
id);
01182 hh->setId(
id);
01183 assert(hh->id());
01184
01185
01186
01187 }
01188
01189
void StiStEventFiller::fillDca(
StTrack* stTrack,
StiKalmanTrack* track)
01190 {
01191
StGlobalTrack *gTrack = dynamic_cast<StGlobalTrack*>(stTrack);
01192 assert(gTrack);
01193
01194
StiKalmanTrackNode *tNode = track->getInnerMostNode();
01195
if (!tNode->
isDca())
return;
01196
const StiNodePars &pars = tNode->
fitPars();
01197
const StiNodeErrs &errs = tNode->
fitErrs();
01198
float alfa = tNode->
getAlpha();
01199
float setp[7],sete[15];
01200 TCL::ucopy(&pars._y,setp,7);
01201 setp[2]+= alfa;
01202
for (
int i=1,li=1,jj=0;i< kNPars;li+=++i) {
01203
for (
int j=1;j<=i;j++) {sete[jj++]=errs.A[li+j];}}
01204
StDcaGeometry *dca =
new StDcaGeometry;
01205 gTrack->
setDcaGeometry(dca);
01206 dca->set(setp,sete);
01207
01208 }
01209
01210
void StiStEventFiller::FillStHitErr(
StHit *hh,
const StiKalmanTrackNode *node)
01211 {
01212
double stiErr[6],stErr[6];
01213 memcpy(stiErr,node->
hitErrs(),
sizeof(stiErr));
01214
double alfa = node->
getAlpha();
01215
double c = cos(alfa);
01216
double s = sin(alfa);
01217
double T[3][3]={{c,-s, 0}
01218 ,{s, c, 0}
01219 ,{0, 0, 1}};
01220
01221 TCL::trasat(T[0],stiErr,stErr,3,3);
01222 StThreeVectorF f3(sqrt(stErr[0]),sqrt(stErr[2]),sqrt(stErr[5]));
01223 hh->setPositionError(f3);
01224 }
01225
01226
void StiStEventFiller::fillPulls(
StiKalmanTrack* track,
int gloPri)
01227 {
01228
01229
if (!mPullEvent)
return;
01230
int dets[kMaxDetectorId][3];
01231 track->getAllPointCount(dets,kMaxDetectorId-1);
01232 StiPullTrk aux;
01233 aux.mTrackNumber=mTrackNumber;
01234 aux.nAllHits = dets[0][2];
01235 aux.nTpcHits = dets[kTpcId][2];
01236 aux.nSvtHits = dets[kSvtId][2];
01237 aux.nSsdHits = dets[kSsdId][2];
01238 aux.nPxlHits = dets[kPxlId][2];
01239 aux.nIstHits = dets[kIstId][2];
01240 aux.mL = (
unsigned char)track->getTrackLength();
01241 aux.mChi2 = track->getChi2();
01242 aux.mCurv = track->getCurvature();
01243 aux.mPt = track->getPt();
01244 aux.mPsi = track->getPhi();
01245 aux.mDip = atan(track->getTanL());
01246 StThreeVectorD v3 = track->getPoint();
01247 aux.mRxy = v3.perp();
01248 aux.mPhi = v3.phi();
01249 aux.mZ = v3.z();
01250 mPullEvent->
Add(aux,gloPri);
01251
01252
01253
StiKTNIterator tNode = track->rbegin();
01254
StiKTNIterator eNode = track->rend();
01255
for (;tNode!=eNode;++tNode)
01256 {
01257
StiKalmanTrackNode *node = &(*tNode);
01258
if(!node->isValid())
continue;
01259
01260
StiHit *stiHit = node->getHit();
01261
if (!stiHit)
continue;
01262
01263
if (node->getChi2()>1000)
continue;
01264
if (!node->isFitted())
continue;
01265
01266
const StiDetector *detector = node->getDetector();
01267 assert(detector == stiHit->
detector());
01268 assert(!detector || stiHit->
timesUsed());
01269
StHit *hh = (
StHit*)stiHit->
stHit();
01270 fillPulls(hh,stiHit,node,track,dets,gloPri);
01271
if (gloPri)
continue;
01272 fillPulls(hh,stiHit,node,track,dets,2);
01273 }
01274 }
01275
01276
void StiStEventFiller::fillPulls(
StHit *stHit,
const StiHit *stiHit
01277 ,
const StiKalmanTrackNode *node
01278 ,
const StiKalmanTrack *track
01279 ,
int dets[1][3],
int gloPriRnd)
01280 {
01281
double x,y,z,r,xp,yp,zp,rp;
01282
float untErrs[3];
01283
01284
const StiNodeInf *inf = 0;
01285
if (gloPriRnd==2) {
01286 inf = node->
getInfo();
01287
if (!inf)
return;
01288 }
01289
const StiNodeErrs &mFE = (inf)? inf->mPE : node->
fitErrs();
01290
const StiNodePars &mFP = (inf)? inf->mPP : node->
fitPars();
01291 StiHitErrs mHrr;
01292 memcpy(mHrr.A, (inf)? inf->mHrr.A : node->
hitErrs(),
sizeof(StiHitErrs));
01293
01294 StiPullHit aux;
01295
01296
01297 aux.nHitCand = node->
getHitCand();
01298 aux.iHitCand = node->
getIHitCand();
01299
if (!aux.nHitCand) aux.nHitCand=1;
01300 aux.lXHit = stiHit->
x();
01301 aux.lYHit = stiHit->
y();
01302 aux.lZHit = stiHit->
z();
01303 aux.lYHitErr = sqrt(mHrr.hYY);
01304 aux.lZHitErr = sqrt(mHrr.hZZ);
01305 aux.lHitEmx[0] = mHrr.hYY;
01306 aux.lHitEmx[1] = mHrr.hZY;
01307 aux.lHitEmx[2] = mHrr.hZZ;
01308
01309
01310 aux.lXFit = mFP._x;
01311 aux.lYFit = mFP._y;
01312 aux.lZFit = mFP._z;
01313 aux.lYFitErr = sqrt(mFE._cYY);
01314 aux.lZFitErr = sqrt(mFE._cZZ);
01315 aux.lFitEmx[0] = mFE._cYY;
01316 aux.lFitEmx[1] = mFE._cZY;
01317 aux.lFitEmx[2] = mFE._cZZ;
01318
01319
01320
01321 xp = aux.lXHit;
01322 yp = (inf)? mFP._y: (
double)node->
unTouched().mPar[0];
01323 zp = (inf)? mFP._z: (
double)node->
unTouched().mPar[1];
01324 aux.lYPul = aux.lYHit-yp;
01325 aux.lZPul = aux.lZHit-zp;
01326
if (fabs(aux.lYPul)>10) StiDebug::Break(-1);
01327
if (fabs(aux.lZPul)>10) StiDebug::Break(-1);
01328
if (!inf) {TCL::ucopy(node->
unTouched().mErr,untErrs,3);}
01329
else {TCL::ucopy(aux.lFitEmx ,untErrs,3);}
01330 assert(untErrs[0]>0);
01331 assert(untErrs[2]>0);
01332 TCL::vadd(untErrs,aux.lHitEmx,aux.lPulEmx,3);
01333 aux.lYPulErr = sqrt(aux.lPulEmx[0]);
01334 aux.lZPulErr = sqrt(aux.lPulEmx[2]);
01335
01336 aux.lPsi = mFP._eta;
01337 aux.lDip = atan(mFP._tanl);
01338
01339
01340
double alfa = node->
getAlpha();
01341
float F[2][2];
01342
01343
01344 x = stiHit->
x(); y = stiHit->
y(); z = stiHit->
z();
01345 r = sqrt(x*x+y*y);
01346
01347 aux.gRHit = r;
01348 aux.gPHit = atan2(stiHit->
y_g(),stiHit->
x_g());
01349 aux.gZHit = stiHit->
z_g();
01350 memset(F[0],0,
sizeof(F));
01351 F[0][0]= x/(r*r);
01352 F[1][1]= 1;
01353 TCL::trasat(F[0],aux.lHitEmx,aux.gHitEmx,2,2);
01354 aux.gPHitErr = sqrt(aux.gHitEmx[0]);
01355 aux.gZHitErr = sqrt(aux.gHitEmx[2]);
01356
01357
01358
01359 x = mFP._x; y = mFP._y;z = mFP._z;
01360 r = sqrt(x*x+y*y);
01361 aux.gRFit = r;
01362 aux.gPFit = NICE(atan2(y,x)+alfa);
01363 aux.gZFit = z;
01364
01365 memset(F[0],0,
sizeof(F));
01366 F[0][0]= x/(r*r);
01367 F[1][1]= 1;
01368 TCL::trasat(F[0],aux.lFitEmx,aux.gFitEmx,2,2);
01369 aux.gPFitErr = sqrt(aux.gFitEmx[0]);
01370 aux.gZFitErr = sqrt(aux.gFitEmx[2]);
01371
01372
01373 rp = sqrt(xp*xp+yp*yp);
01374 aux.gPPul = ((aux.gPHit-alfa)-atan2(yp,xp))*rp;
01375 aux.gZPul = aux.lZHit-zp;
01376 memset(F[0],0,
sizeof(F));
01377 F[0][0]= xp/(rp*rp);
01378 F[1][1]= 1;
01379 TCL::trasat(F[0],untErrs,aux.gPulEmx,2,2);
01380 TCL::vadd(aux.gHitEmx,aux.gPulEmx,aux.gPulEmx,3);
01381
01382 aux.gPulEmx[0]*= rp*rp;
01383 aux.gPulEmx[1]*= rp;
01384 aux.gPPulErr = sqrt(aux.gPulEmx[0]);
01385 aux.gZPulErr = sqrt(aux.gPulEmx[2]);
01386
01387 aux.gPsi = node->
getPsi();
01388 aux.gDip = node->
getDipAngle();
01389
01390
01391 aux.mCurv = mFP._curv;
01392 aux.mPt = fabs(1./mFP._ptin);
01393 aux.mChi2 = node->getChi2();
01394 aux.mNormalRefAngle = alfa;
01395 aux.mHardwarePosition=0;
01396 aux.mDetector=0;
01397 aux.mTrackNumber=mTrackNumber;
01398 aux.nAllHits = dets[0][2];
01399 aux.nTpcHits = dets[kTpcId][2];
01400 aux.nSvtHits = dets[kSvtId][2];
01401 aux.nSsdHits = dets[kSsdId][2];
01402 aux.nPxlHits = dets[kPxlId][2];
01403 aux.nIstHits = dets[kIstId][2];
01404
const StiDetector *stiDet = stiHit->
detector();
01405
if (stiDet) {
01406 aux.mHardwarePosition=stHit->
hardwarePosition();
01407 aux.mDetector=stHit->
detector();
01408
const StiPlacement *place = stiDet->
getPlacement();
01409 aux.mNormalRadius = place->getNormalRadius();
01410 aux.mNormalYOffset = place->getNormalYoffset();
01411 aux.mZCenter = 0;
01412 }
01413 mPullEvent->
Add(aux,gloPriRnd);
01414
01415 }