00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <StMessMgr.h>
00013 #include <TGraphErrors.h>
00014 #include <TF1.h>
00015 #include <TH2.h>
00016 #include <TFile.h>
00017 #include <TLine.h>
00018 #include <TCanvas.h>
00019
00020 #include <math_constants.h>
00021 #include <tables/St_g2t_vertex_Table.h>
00022
00023 #include "StPPVertexFinder.h"
00024 #include "TrackData.h"
00025 #include "VertexData.h"
00026 #include "Vertex3D.h"
00027 #include "StGenericVertexMaker/StGenericVertexMaker.h"
00028
00029 #include <Sti/StiToolkit.h>
00030 #include <Sti/StiKalmanTrack.h>
00031 #include <Sti/StiKalmanTrackNode.h>
00032 #include <Sti/StiTrackContainer.h>
00033
00034 #include <St_db_Maker/St_db_Maker.h>
00035 #include <StIOMaker/StIOMaker.h>
00036 #include <StBFChain/StBFChain.h>
00037
00038 #define xL(t) (t->getX())
00039 #define yL(t) (t->getY())
00040 #define eyL(t) sqrt(t->getCyy())
00041 #define zL(t) (t->getZ())
00042 #define ezL(t) sqrt(t->getCzz())
00043 #define rxyL(t) sqrt(xL(t)*xL(t) + yL(t)*yL(t))
00044 #define xG(t) (t->x_g())
00045 #define yG(t) (t->y_g())
00046 #define zG(t) (t->z_g())
00047 #define rxyG(t) sqrt(xG(t)*xG(t) + yG(t)*yG(t))
00048
00049 #include <StEEmcUtil/database/StEEmcDb.h>
00050 #include <StEEmcUtil/database/EEmcDbItem.h>
00051 #include <StEEmcUtil/database/cstructs/eemcConstDB.hh>
00052 #include <StEEmcUtil/EEmcGeom/EEmcGeomSimple.h>
00053
00054 #include "BtofHitList.h"
00055 #include "CtbHitList.h"
00056 #include "BemcHitList.h"
00057 #include "EemcHitList.h"
00058
00059 #include "StEmcCollection.h"
00060 #include "StBTofCollection.h"
00061 #include "StBTofUtil/StBTofGeometry.h"
00062 #include "TObjectSet.h"
00063
00064
00065
00066
00067 StPPVertexFinder::StPPVertexFinder() {
00068 LOG_INFO << "StPPVertexFinder::StPPVertexFinder is in use" << endm;
00069
00070 mdxdz=mdydz=mX0=mY0 = 0;
00071 mTotEve = 0;
00072 HList=0;
00073 mToolkit =0;
00074 memset(hA,0,sizeof(hA));
00075
00076 setMC(false);
00077 useCTB(true);
00078 setDropPostCrossingTrack(true);
00079 mVertexOrderMethod = orderByRanking;
00080
00081 mAlgoSwitches=0;
00082
00083
00084 mAlgoSwitches|=kSwitchOneHighPT;
00085 mCut_oneTrackPT=10;
00086 mBeamLineTracks=0;
00087
00088
00089 int nb=5000;
00090 float zRange=250;
00091 hL=new TH1D("ppvL","Vertex likelyhood; Z /cm",nb,-zRange,zRange);
00092
00093 hM=new TH1D("ppvM","cumulative track multiplicity; Z /cm",nb,-zRange,zRange);
00094 hW=new TH1D("ppvW","cumulative track weight; Z /cm",nb,-zRange,zRange);
00095
00096 }
00097
00098
00099
00100
00101 void
00102 StPPVertexFinder::Init() {
00103 assert(mTotEve==0);
00104 LOG_INFO << Form("PPV-algo switches=0x%0x, following cuts have been activated:",mAlgoSwitches)<<endm;
00105
00106 mMaxTrkDcaRxy = 3.0;
00107 mMinTrkPt = 0.20;
00108 mMinFitPfrac = 0.7;
00109 mMaxZradius = 3.0;
00110 mMaxZrange = 200;
00111 mMinMatchTr = 2;
00112 mDyBtof = 1.5;
00113 mMinZBtof = -3.0;
00114 mMaxZBtof = 3.0;
00115 mMinAdcEemc = 5;
00116
00117 mStoreUnqualifiedVertex=5;
00118
00119
00120
00121 mToolkit = StiToolkit::instance();
00122 assert(mToolkit);
00123
00124 ctbList =new CtbHitList;
00125 bemcList =new BemcHitList;
00126 btofList = new BtofHitList;
00127 vertex3D=0;
00128
00129
00130 eeDb = (StEEmcDb*)StMaker::GetChain()->GetDataSet("StEEmcDb");
00131 assert(eeDb);
00132 cout<<"eeDb done"<<endl;
00133 geomE= new EEmcGeomSimple();
00134
00135 uint killStatEEmc=EEMCSTAT_ONLPED | EEMCSTAT_STKBT| EEMCSTAT_HOTHT | EEMCSTAT_HOTJP | EEMCSTAT_JUMPED ;
00136 eemcList =new EemcHitList(eeDb, killStatEEmc,geomE);
00137
00138 HList=new TObjArray(0);
00139 initHisto();
00140 cout<<"initiated histos"<<endl;
00141 if (mUseBtof)
00142 btofList->initHisto( HList);
00143 ctbList->initHisto( HList);
00144 bemcList->initHisto( HList);
00145 eemcList->initHisto( HList);
00146 cout<<"Finished Init"<<endl;
00147 }
00148
00149
00150
00151 void
00152 StPPVertexFinder::InitRun(int runnumber){
00153 LOG_INFO << "PPV InitRun() runNo="<<runnumber<<endm;
00154 St_db_Maker* mydb = (St_db_Maker*) StMaker::GetChain()->GetMaker("db");
00155 int dateY=mydb->GetDateTime().GetYear();
00156
00157 if(isMC) assert(runnumber <1000000);
00158
00159 if (mUseBtof){
00160 btofGeom = 0;
00161 TObjectSet *geom = (TObjectSet *) mydb->GetDataSet("btofGeometry");
00162 if (geom) btofGeom = (StBTofGeometry *) geom->GetObject();
00163 if (btofGeom) {
00164 LOG_INFO << " Found btofGeometry ... " << endm;
00165 } else {
00166 btofGeom = new StBTofGeometry("btofGeometry","btofGeometry in VertexFinder");
00167 geom = new TObjectSet("btofGeometry",btofGeom);
00168 LOG_INFO << " Create a new btofGeometry ... " << endm;
00169 mydb->AddConst(geom);
00170 }
00171 if(btofGeom && !btofGeom->IsInitDone()) {
00172 LOG_INFO << " BTofGeometry initialization ... " << endm;
00173 TVolume *starHall = (TVolume *)mydb->GetDataSet("HALL");
00174 btofGeom->Init(mydb, starHall);
00175 mydb->AddConst(new TObjectSet("btofGeometry",btofGeom));
00176 }
00177 }
00178
00179 if(isMC) {
00180 LOG_INFO << "PPV InitRun() M-C, Db_date="<<mydb->GetDateTime().AsString()<<endm;
00181
00182 mMinAdcBemc =7;
00183
00184 if(dateY>=2008) mMinAdcBemc =8;
00185
00186 if(dateY>2006) LOG_WARN <<
00187 "PPV InitRun() , M-C time stamp differs from 2005,\n BTOW status tables questionable,\n PPV results qauestionable, \n\n F I X B T O W S T A T U S T A B L E S B E F O R E U S E !!! \n \n chain will continue taking whatever is loaded in to DB\n Jan Balewski, January 2006\n"<<endm;
00188 }
00189
00190 if(dateY<2006) {
00191 mMinAdcBemc = 15;
00192 } else {
00193 mMinAdcBemc = 8;
00194 }
00195 if (mUseBtof)
00196 btofList->initRun();
00197 ctbList->initRun();
00198 bemcList->initRun();
00199 eemcList->initRun();
00200
00201 if(mBeamLineTracks){
00202 assert(vertex3D==0);
00203 vertex3D=new Vertex3D;
00204 vertex3D->setCuts(0.8,8.0, 3.3,5);
00205 vertex3D->initHisto( HList);
00206 vertex3D->initRun();
00207 }
00208
00209 gMessMgr->Message("","I")
00210 << "PPV::cuts "
00211 <<"\n MinFitPfrac=nFit/nPos ="<< mMinFitPfrac
00212 <<"\n MaxTrkDcaRxy/cm="<<mMaxTrkDcaRxy
00213 <<"\n MinTrkPt GeV/c ="<<mMinTrkPt
00214 <<"\n MinMatchTr of prim tracks ="<< mMinMatchTr
00215 <<"\n MaxZrange (cm)for glob tracks ="<< mMaxZrange
00216 <<"\n MaxZradius (cm) for prim tracks &Likelihood ="<< mMaxZradius
00217 <<"\n DeltaY (cm) for BTOF local posision = "<< mDyBtof
00218 <<"\n Min/Max Z position for BTOF hit = "<<mMinZBtof<<" "<<mMaxZBtof
00219 <<"\n MinAdcBemc for MIP ="<<mMinAdcBemc
00220 <<"\n MinAdcEemc for MIP ="<<mMinAdcEemc
00221 <<"\n bool isMC ="<<isMC
00222 <<"\n bool useCtb ="<<mUseCtb
00223 <<"\n bool useBtof ="<<mUseBtof
00224 <<"\n bool DropPostCrossingTrack ="<<mDropPostCrossingTrack
00225 <<"\n Store # of UnqualifiedVertex ="<<mStoreUnqualifiedVertex
00226 <<"\n Store="<<(mAlgoSwitches & kSwitchOneHighPT)<<" oneTrack-vertex if track PT/GeV>"<< mCut_oneTrackPT
00227 <<"\n dump tracks for beamLine study ="<<mBeamLineTracks
00228 <<"\n"
00229 <<endm;
00230
00231 }
00232
00233
00234
00235 void
00236 StPPVertexFinder::initHisto() {
00237 assert(HList);
00238 hA[0]=new TH1F("ppvStat","event types; 1=inp, 2=trg, 3=-, 4=w/trk, 5=anyMch, 6=Bmch 7=Emch 8=anyV, 9=mulV",10,0.5,10.5);
00239 hA[1]=new TH1F("ch1","chi2/Dof, ppv pool tracks",100,0,10);
00240 hA[2]=new TH1F("nP","No. of fit points, ppv pool tracks",30,-.5,59.5);
00241 hA[3]=new TH1F("zV","reconstructed vertices ; Z (cm)",100,-200,200);
00242 hA[4]=new TH1F("nV","No. of vertices per eve",20,-0.5,19.5);
00243
00244 hA[5]=new TH1F("rxyDca","Rxy to beam @ DCA ; (cm)",40,-0.1,3.9);
00245 hA[6]=new TH1F("nTpcM","No. tracks: tpcMatch /eve ",60,-.5,59.5);
00246 hA[7]=new TH1F("nTpcV","No. tracks: tpcVeto /eve ",60,-.5,59.5);
00247
00248 hA[8]=0;
00249
00250 hA[9]=new TH1F("zDca","Z DCA for all accepted tracks; Z (cm)",100,-200,200);
00251
00252 hA[10]=new TH1F("zCtb","Z @CTB for all accepted tracks; Z (cm)",50,-250,250);
00253 hA[11]=new TH1F("zBemc","Z @Bemc for all accepted tracks; Z (cm)",100,-400,400);
00254 hA[12]=new TH1F("dzVerTr","zVerGeant - zDca of tracks used by any vertex ; (cm)",100,-5,5);
00255 hA[13]=new TH1F("dzVerVer","zVerGeant - best reco vertex ; (cm)",100,-5,5);
00256
00257 hA[14]=new TH1F("EzDca","Error of Z DCA for all accepted tracks; Z (cm)",100,-0.,4);
00258 hA[15]=new TH1F("nTpcT","No. tracks: accepted Dca /eve ",201,-.5,200.5);
00259 hA[16]=new TH1F("ptTr","pT, ppv pool tracks; pT (GeV/c) ",50,0.,10.);
00260 hA[17]=new TH1F("vRL","PPV Vertex rank, 'funny' X-axis; X=Log10(rank-1e6)+offset", 150, -11,25);
00261
00262 hACorr=new TH2F("BTOFvsBEMC","BTOF vs BEMC", 5,-2.5,2.5,5,-2.5,2.5);
00263
00264 int i;
00265 for(i=0;i<mxH; i++) if(hA[i]) HList->Add(hA[i]);
00266 HList->Add(hACorr);
00267 }
00268
00269
00270
00271 void
00272 StPPVertexFinder::Clear(){
00273 LOG_DEBUG << "PPVertex::Clear nEve="<<mTotEve<< endm;
00274 StGenericVertexFinder::Clear();
00275 btofList->clear();
00276 ctbList->clear();
00277 bemcList->clear();
00278 eemcList->clear();
00279 mTrackData.clear();
00280 mVertexData.clear();
00281 eveID=-1;
00282
00283
00284 hL->Reset();
00285 hM->Reset();
00286 hW->Reset();
00287
00288
00289 }
00290
00291
00292
00293
00294 StPPVertexFinder::~StPPVertexFinder() {
00295
00296
00297 delete geomE;
00298
00299 }
00300
00301
00302
00303 void
00304 StPPVertexFinder::printInfo(ostream& os) const
00305 {
00306 os << "StPPVertexFinder ver=1 - Fit Statistics:" << endl;
00307
00308 os << "StPPVertexFinder::result "<<mVertexData.size()<<" vertices found\n" << endl;
00309
00310 int nTpcM=0, nTpcV=0;
00311 uint i;
00312 int k=0;
00313 for(i=0;i<mTrackData.size();i++) {
00314 const TrackData *t=&mTrackData[i];
00315 if( t->mTpc>0) nTpcM++;
00316 else if ( t->mTpc<0) nTpcV++;
00317 hA[9]->Fill(t->zDca);
00318 hA[14]->Fill(t->ezDca);
00319 if(t->vertexID<=0) continue;
00320 k++;
00321 LOG_DEBUG
00322 <<
00323 Form("%d track@z0=%.2f +/- %.2f gPt=%.3f vertID=%d match: bin,Fired,Track:\n",
00324 k,t->zDca,t->ezDca,t->gPt,t->vertexID)
00325 << Form(" Btof %3d,%d,%d",t->btofBin,btofList->getFired(t->btofBin),btofList->getTrack(t->btofBin))
00326 << Form(" CTB %3d,%d,%d",t->ctbBin,ctbList->getFired(t->ctbBin),ctbList->getTrack(t->ctbBin))
00327 << Form(" Bemc %3d,%d,%d",t->bemcBin,bemcList->getFired(t->bemcBin),bemcList->getTrack(t->bemcBin))
00328 << Form(" Eemc %3d,%d,%d",t->eemcBin,eemcList->getFired(t->eemcBin),bemcList->getTrack(t->bemcBin))
00329 << Form(" TPC %d",t->mTpc)
00330 <<endm;
00331 }
00332 hA[6]->Fill(nTpcM);
00333 hA[7]->Fill(nTpcV);
00334 hA[15]->Fill(mTrackData.size());
00335
00336 LOG_INFO<< Form("PPVend eveID=%d, list of found %d vertices from pool of %d tracks\n",eveID,mVertexData.size(),mTrackData.size())<<endm;
00337 for(i=0;i<mVertexData.size();i++) {
00338 const VertexData *V=& mVertexData[i];
00339 V->print(os);
00340 }
00341 float zGeant=999;
00342
00343 if(isMC) {
00344
00345 St_DataSet *gds=StMaker::GetChain()->GetDataSet("geant");
00346 assert(gds);
00347 St_g2t_vertex *g2t_ver=( St_g2t_vertex *)gds->Find("g2t_vertex");
00348 if(g2t_ver) {
00349
00350 g2t_vertex_st *GVER= g2t_ver->GetTable();
00351 zGeant=GVER->ge_x[2];
00352 printf("#GVER z=%.1f x=%.1f y=%.1f nEve=%d nV=%d ",zGeant,GVER->ge_x[0],GVER->ge_x[1],mTotEve,mVertexData.size());
00353 }
00354 }
00355
00356 if(isMC) {
00357 for(i=0;i<mTrackData.size();i++) {
00358 const TrackData *t=&mTrackData[i];
00359 if(t->vertexID<=0) continue;
00360 hA[12]->Fill(zGeant-t->zDca);
00361 }
00362 }
00363
00364 LOG_DEBUG<< Form("---- end of PPVertex Info\n")<<endm;
00365
00366 }
00367
00368
00369
00370 void
00371 StPPVertexFinder::CalibBeamLine(){
00372 LOG_INFO << "StPPVertexFinder::CalibBeamLine: activated saving high quality prim tracks for 3D fit of the beamLine"<<endm;
00373 mBeamLineTracks=1;
00374 }
00375
00376
00377
00378 void
00379 StPPVertexFinder::UseVertexConstraint(double x0, double y0, double dxdz, double dydz, double weight) {
00380 mVertexConstrain = true;
00381 mX0 = x0;
00382 mY0 = y0;
00383 mdxdz = dxdz;
00384 mdydz = dydz;
00385
00386
00387 LOG_INFO << "StPPVertexFinder::Using Constrained Vertex" << endm;
00388 LOG_INFO << "x origin = " << mX0 << endm;
00389 LOG_INFO << "y origin = " << mY0 << endm;
00390 LOG_INFO << "slope dxdz = " << mdxdz << endm;
00391 LOG_INFO << "slope dydz = " << mdydz << endm;
00392
00393 }
00394
00395
00396
00397
00398 int
00399 StPPVertexFinder::fit(StEvent* event) {
00400 cout<<"***** START FIT"<<endl;
00401 if(mBeamLineTracks) vertex3D->clearEvent();
00402
00403 hA[0]->Fill(1);
00404
00405 StEvent *mEvent = (StEvent *) StMaker::GetChain()->GetInputDS("StEvent");
00406 assert(mEvent);
00407
00408 #if 0 // do you want trigger filter?
00409
00410 StTriggerIdCollection *ticA=mEvent->triggerIdCollection();
00411 assert(ticA);
00412 const StTriggerId *L1=L1=ticA->nominal();
00413
00414 vector<unsigned int> trgL=L1->triggerIds();
00415 printf("PPVertex::Fit START trigL len=%d \n",trgL.size());
00416 uint ii;
00417 for(ii=0;ii<trgL.size();ii++){
00418 printf("ii=%d trigID=%d\n",ii,trgL[ii]);
00419 }
00420
00421 if(L1->isTrigger(127221)==0) {
00422 printf("PPV is off for this trigger(s)\n");
00423 return false;
00424 }
00425 #endif
00426
00427
00428 mTotEve++;
00429 eveID=event->id();
00430 LOG_INFO << "\n @@@@@@ PPVertex::Fit START nEve="<<mTotEve<<" eveID="<<eveID<< endm;
00431
00432 TString tt="Vertex likelyhood, eveID=";
00433 tt+=eveID;
00434 hL->SetTitle(tt);
00435
00436 hA[0]->Fill(2);
00437
00438 if(mToolkit==0) {
00439 LOG_WARN <<"no Sti tool kit, PPV is OFF"<<endm;
00440 return 0;
00441 }
00442
00443
00444
00445 if(mUseBtof) {
00446 StBTofCollection *btofColl = (StBTofCollection*)mEvent->btofCollection();
00447 if(btofColl==0) {
00448 LOG_WARN << "no btofCollection , continue THE SAME eve"<<endm;
00449 } else {
00450 btofList->build(btofColl);
00451 }
00452 }
00453
00454
00455 if(mUseCtb) {
00456 if(isMC){
00457 St_DataSet *gds=StMaker::GetChain()->GetDataSet("geant");
00458 ctbList->buildFromMC(gds);
00459 } else {
00460 StTriggerData *trgD=event->triggerData ();
00461 ctbList->buildFromData(trgD);
00462 }
00463 }
00464
00465
00466 StEmcCollection* emcC =(StEmcCollection*)mEvent->emcCollection();
00467 if(emcC==0) {
00468 LOG_WARN <<"no emcCollection , continue THE SAME eve"<<endm;
00469 } else {
00470 assert(emcC);
00471 StEmcDetector* btow = emcC->detector( kBarrelEmcTowerId);
00472 if(btow==0) {
00473 LOG_WARN <<"no BEMC in emcColl , continue THE SAME eve"<<endm;
00474 } else {
00475 assert(btow);
00476 bemcList->build(btow, mMinAdcBemc);
00477 }
00478
00479 StEmcDetector* etow = emcC->detector(kEndcapEmcTowerId);
00480 if(etow==0) {
00481 LOG_WARN <<"no EEMC in emcColl , continue THE SAME eve"<<endm;
00482 } else {
00483 assert(etow);
00484 eemcList->build(etow, mMinAdcEemc);
00485 }
00486 }
00487
00488
00489 StiTrackContainer* tracks = mToolkit->getTrackContainer();
00490 if(tracks==0) {
00491 LOG_WARN <<"no STi tracks , skip eve"<<endm;
00492 printInfo();
00493 return 0 ;
00494 }
00495
00496 hA[0]->Fill(4);
00497
00498
00499 int k=0;
00500 int kBtof=0,kCtb=0,kBemc=0, kEemc=0,kTpc=0;
00501 int nmAny=0;
00502
00503 int ntrk[7]; for(int i=0; i<7; i++) ntrk[i]=0;
00504
00505 for (StiTrackContainer::const_iterator it=(*tracks).begin(); it!=(*tracks).end(); ++it) {
00506 k++;
00507 const StiKalmanTrack* track = static_cast<StiKalmanTrack*>(*it);
00508 TrackData t;
00509
00510 ntrk[0]++;
00511 if(track->getFlag()!=true) {ntrk[1]++; continue;}
00512 if(track->getPt()<mMinTrkPt) {ntrk[2]++; continue;}
00513 if(mDropPostCrossingTrack){
00514 if(isPostCrossingTrack(track)) {ntrk[3]++; continue;}
00515 }
00516 if(!examinTrackDca(track,t)) {ntrk[4]++; continue;}
00517 if(!matchTrack2Membrane(track,t)) {ntrk[5]++; continue;}
00518 ntrk[6]++;
00519
00520
00521
00522 hA[1]->Fill(track->getChi2());
00523 hA[2]->Fill(track->getFitPointCount());
00524 hA[16]->Fill(track->getPt());
00525
00526
00527
00528 if(mUseBtof) matchTrack2BTOF(track,t,btofGeom);
00529 if(mUseCtb) matchTrack2CTB(track,t);
00530 matchTrack2BEMC(track,t,242);
00531 matchTrack2EEMC(track,t,288);
00532
00533 t.mother=track;
00534 mTrackData.push_back(t);
00535
00536 hA[5]->Fill(t.rxyDca);
00537
00538 if( t.mBtof>0 ) kBtof++;
00539 if( t.mCtb>0 ) kCtb++;
00540 if( t.mBemc>0) kBemc++;
00541 if( t.mEemc>0) kEemc++;
00542 if( t.mTpc>0 ) kTpc++;
00543
00544 if(t.mBtof>0 || t.mCtb>0 || t.mBemc>0 || t.mEemc>0 || t.mTpc>0 ) nmAny++ ;
00545
00546 hACorr->Fill(t.mBtof, t.mBemc);
00547
00548 }
00549
00550 LOG_INFO<< Form("PPV:: # of input track = %d",ntrk[0])<<endm;
00551 LOG_INFO<< Form("PPV:: dropped due to flag = %d",ntrk[1])<<endm;
00552 LOG_INFO<< Form("PPV:: dropped due to pt = %d",ntrk[2])<<endm;
00553 LOG_INFO<< Form("PPV:: dropped due to PCT check = %d",ntrk[3])<<endm;
00554 LOG_INFO<< Form("PPV:: dropped due to DCA check = %d",ntrk[4])<<endm;
00555 LOG_INFO<< Form("PPV:: dropped due to NHit check = %d",ntrk[5])<<endm;
00556 LOG_INFO<< Form("PPV:: # of track after all cuts = %d",ntrk[6])<<endm;
00557
00558 if(mUseCtb) {
00559 ctbList ->print();
00560 ctbList ->doHisto();
00561 }
00562
00563 if(mUseBtof) {
00564 btofList->print();
00565 btofList->doHisto();
00566 }
00567
00568 bemcList->print();
00569 eemcList->print();
00570 LOG_INFO<< Form("PPV::TpcList size=%d nMatched=%d\n\n",mTrackData.size(),kTpc)<<endm;
00571
00572 bemcList->doHisto();
00573 eemcList->doHisto();
00574
00575 LOG_INFO << "PPV::fit() nEve="<<mTotEve<<" , "<<nmAny<<" traks with good DCA, matching: BTOF="<<kBtof<<" CTB="<<kCtb<<" BEMC="<<kBemc<<" EEMC="<<kEemc<<endm;
00576
00577
00578 if(nmAny<mMinMatchTr && mStoreUnqualifiedVertex<=0){
00579 LOG_INFO << "StPPVertexFinder::fit() nEve="<<mTotEve<<" Quit, to few matched tracks"<<endm;
00580 printInfo();
00581 return 0;
00582 }
00583 hA[0]->Fill(5);
00584
00585 if(kBemc) hA[0]->Fill(6);
00586 if(kEemc) hA[0]->Fill(7);
00587
00588
00589
00590
00591
00592 const float par_rankOffset=1e6;
00593
00594 int nBadVertex=0;
00595 int vertexID=0;
00596 while(1) {
00597 if(! buildLikelihoodZ() ) break;
00598 VertexData V;
00599 V.id=++vertexID;
00600 if(! findVertexZ(V)) break;
00601
00602 bool trigV=evalVertexZ(V);
00603
00604 if(V.nAnyMatch>=mMinMatchTr) V.Lmax+=par_rankOffset;
00605 if(!trigV) {
00606 if( nBadVertex>=mStoreUnqualifiedVertex) continue;
00607
00608
00609
00610 nBadVertex++;
00611
00612 V.Lmax-=par_rankOffset;
00613 }
00614
00615 {
00616 float rank=V.Lmax;
00617 if(rank>1e6) hA[17]->Fill(log(rank-1e6)+10);
00618 else if(rank>0) hA[17]->Fill(log(rank));
00619 else hA[17]->Fill(log(rank+1e6)-10);
00620 }
00621
00622 mVertexData.push_back(V);
00623 if(trigV && mBeamLineTracks) vertex3D->study(V.r,eveID);
00624 }
00625
00626 LOG_INFO << "StPPVertexFinder::fit(totEve="<<mTotEve<<") "<<mVertexData.size()<<" vertices found, nBadVertex=" <<nBadVertex<< endm;
00627
00628 if(mVertexData.size()>0) hA[0]->Fill(8);
00629 if(mVertexData.size()>1) hA[0]->Fill(9);
00630
00631 exportVertices();
00632 printInfo();
00633
00634 hA[4]->Fill(mVertexData.size());
00635 uint i;
00636 for(i=0;i<mVertexData.size();i++) {
00637 VertexData *V=&mVertexData[i];
00638 hA[3]->Fill(V->r.z());
00639 }
00640
00641 if(mVertexData.size()<=0) {
00642 return 0;
00643 }
00644
00645 return size();
00646 }
00647
00648
00649
00650
00651 bool
00652 StPPVertexFinder::buildLikelihoodZ(){
00653 hL->Reset();
00654 hM->Reset();
00655 hW->Reset();
00656
00657 float dzMax2=mMaxZradius*mMaxZradius;
00658
00659 int nt=mTrackData.size();
00660 LOG_DEBUG<< Form("PPV::buildLikelihood() pool of nTracks=%d",nt)<<endm;
00661 if(nt<=0) return false;
00662
00663 int n1=0;
00664 int i;
00665
00666 double *La=hL->GetArray();
00667 double *Ma=hM->GetArray();
00668 double *Wa=hW->GetArray();
00669
00670 for(i=0;i<nt;i++) {
00671 const TrackData *t=&mTrackData[i];
00672 if(t->vertexID!=0) continue;
00673 if(t->anyMatch) n1++;
00674
00675 float z0=t->zDca;
00676 float ez=t->ezDca;
00677 float ez2=ez*ez;
00678 int j1=hL->FindBin(z0-mMaxZradius-.1);
00679 int j2=hL->FindBin(z0+mMaxZradius+.1);
00680 float base=dzMax2/2/ez2;
00681 float totW=t->weight;
00682
00683
00684 int j;
00685 for(j=j1;j<=j2;j++) {
00686 float z=hL->GetBinCenter(j);
00687 float dz=z-z0;
00688 float xx=base-dz*dz/2/ez2;
00689 if(xx<=0) continue;
00690 La[j]+=xx*totW;
00691 Ma[j]+=1.;
00692 Wa[j]+=totW;
00693
00694 }
00695
00696 }
00697
00698 LOG_DEBUG<< Form("PPV::buildLikelihood() %d tracks w/ matched @ Lmax=%f",n1,hL->GetMaximum())<<endm;
00699
00700 #if 0 // save .ps for every vertex found
00701
00702 LOG_WARN << "PPV saves .ps for every vertex, jan"<<endm;
00703 TCanvas c;
00704 hL->Draw();
00705 TString tt="eve";
00706 tt+=eveID; tt+="Lmx"; tt+=hL->GetMaximum();
00707 c.Print(tt+".ps");
00708 #endif
00709
00710 return (n1>=mMinMatchTr) || (mStoreUnqualifiedVertex>0 );
00711 }
00712
00713
00714
00715 bool
00716 StPPVertexFinder::findVertexZ(VertexData &V) {
00717
00718 if(hL->GetMaximum()<=0) return false;
00719
00720 int iMax=hL-> GetMaximumBin();
00721 float z0=hL-> GetBinCenter(iMax);
00722 float Lmax=hL-> GetBinContent(iMax);
00723 float accM=hM-> GetBinContent(iMax);
00724 float accW=hW-> GetBinContent(iMax);
00725 assert(accM>0);
00726 float avrW=accW/accM;
00727
00728
00729 float Llow=0.9* Lmax;
00730 if((Lmax-Llow)<8*avrW ) Llow=Lmax-8*avrW;
00731 int i;
00732 double *L=hL->GetArray();
00733
00734 int iLow=-1, iHigh=-1;
00735 for(i=iMax;i<=hL->GetNbinsX();i++) {
00736 if(L[i] >Llow) continue;
00737 iHigh=i;
00738 break;
00739 }
00740 for(i=iMax;i>=1;i--) {
00741 if(L[i] >Llow) continue;
00742 iLow=i;
00743 break;
00744 }
00745
00746 float zLow=hL-> GetBinCenter(iLow);
00747 float zHigh=hL-> GetBinCenter(iHigh);
00748
00749 float kSig= sqrt(2*(Lmax-Llow)/avrW);
00750 float sigZ= (zHigh-zLow)/2/kSig;
00751 LOG_DEBUG<< Form("PPV:: iLow/iMax/iHigh=%d/%d/%d\n",iLow,iMax,iHigh)
00752 <<Form(" accM=%f accW=%f avrW=%f\n",accM,accW,avrW)
00753 <<Form(" Z low/max/high=%f %f %f, kSig=%f, sig=%f\n",zLow,z0,zHigh,kSig,sigZ)
00754 <<Form(" found PPVertex(ID=%d,neve=%d) z0 =%.2f +/- %.2f\n",V.id,mTotEve,z0,sigZ)<<endm;
00755 if(sigZ<0.1) sigZ=0.1;
00756
00757
00758 float x=mX0+z0*mdxdz;
00759 float y=mY0+z0*mdydz;
00760
00761 V.r=TVector3(x,y,z0);
00762 V.er=TVector3(0.1,0.1,sigZ);
00763 V.Lmax=Lmax;
00764
00765 return true;
00766 }
00767
00768
00769
00770 bool
00771 StPPVertexFinder::evalVertexZ(VertexData &V) {
00772
00773 if(mBeamLineTracks) vertex3D->clearTracks();
00774 int nt=mTrackData.size();
00775 LOG_DEBUG << "StPPVertexFinder::evalVertex Vid="<<V.id<<" start ..."<<endm;
00776 int n1=0, nHiPt=0;
00777 int i;
00778
00779 for(i=0;i<nt;i++) {
00780 TrackData *t=&mTrackData[i];
00781 if(t->vertexID!=0) continue;
00782 if(! t->matchVertex(V,mMaxZradius)) continue;
00783
00784 n1++;
00785 t->vertexID=V.id;
00786 V.gPtSum+=t->gPt;
00787 if(mBeamLineTracks) vertex3D->addTrack(t);
00788 if( t->gPt>mCut_oneTrackPT && ( t->mBemc>0|| t->mEemc>0) ) nHiPt++;
00789
00790 if( t->mTpc>0) V.nTpc++;
00791 else if ( t->mTpc<0) V.nTpcV++;
00792
00793 if( t->mBtof>0) V.nBtof++;
00794 else if ( t->mBtof<0) V.nBtofV++;
00795
00796 if( t->mCtb>0) V.nCtb++;
00797 else if ( t->mCtb<0) V.nCtbV++;
00798
00799 if( t->mBemc>0) V.nBemc++;
00800 else if ( t->mBemc<0) V.nBemcV++;
00801
00802 if( t->mEemc>0) V.nEemc++;
00803 else if ( t->mEemc<0) V.nEemcV++;
00804
00805 if( t->anyMatch) V.nAnyMatch++;
00806 else if (t->anyVeto) V.nAnyVeto++;
00807 }
00808 V.nUsedTrack=n1;
00809
00810 bool validVertex = V.nAnyMatch>=mMinMatchTr;
00811 if((mAlgoSwitches & kSwitchOneHighPT) && ( nHiPt>0)) {
00812 validVertex|=1;
00813 }
00814
00815 if(!validVertex) {
00816
00817
00818 LOG_DEBUG << "StPPVertexFinder::evalVertex Vid="<<V.id<<" rejected"<<endm;
00819 for(i=0;i<nt;i++) {
00820 TrackData *t=&mTrackData[i];
00821 if(t->vertexID!=V.id) continue;
00822 t->vertexID=-V.id;
00823 }
00824 return false;
00825 }
00826
00827 LOG_INFO << "StPPVertexFinder::evalVertex Vid="<<V.id<<" accepted, nAnyMatch="<<V.nAnyMatch<<" nAnyVeto="<<V.nAnyVeto<<endm;
00828 return true;
00829 }
00830
00831
00832
00833
00834 void
00835 StPPVertexFinder::exportVertices(){
00836 if ( ! mVertexConstrain ){
00837
00838 LOG_FATAL << "StPPVertexFinder code is not ready for reco w/o beamLine" << endm;
00839 assert(mVertexConstrain);
00840 }
00841 uint i;
00842 for(i=0;i<mVertexData.size();i++) {
00843 VertexData *V=&mVertexData[i];
00844 StThreeVectorD r(V->r.x(),V->r.y(),V->r.z());
00845
00846 Float_t cov[6];
00847 memset(cov,0,sizeof(cov));
00848 cov[0]=V->er.x()*V->er.x();
00849 cov[2]=V->er.y()*V->er.y();
00850 cov[5]=V->er.z()*V->er.z();
00851
00852 StPrimaryVertex primV;
00853 primV.setPosition(r);
00854 primV.setCovariantMatrix(cov);
00855
00856 if(mUseCtb) primV.setVertexFinderId(ppvVertexFinder);
00857 else primV.setVertexFinderId(ppvNoCtbVertexFinder);
00858
00859 primV.setNumTracksUsedInFinder(V->nUsedTrack);
00860 primV.setNumMatchesWithBTOF(V->nBtof);
00861 primV.setNumMatchesWithCTB(V->nCtb);
00862 primV.setNumMatchesWithBEMC(V->nBemc);
00863 primV.setNumMatchesWithEEMC(V->nEemc);
00864 primV.setNumTracksCrossingCentralMembrane(V->nTpc);
00865 primV.setSumOfTrackPt(V->gPtSum);
00866 primV.setRanking(V->Lmax);
00867 primV.setFlag(1);
00868
00869
00870 addVertex(&primV);
00871 }
00872 LOG_DEBUG << "StPPVertexFinder::exportVertices(), size="<<size()<<endm;
00873 }
00874
00875
00876
00877 void
00878 StPPVertexFinder::Finish() {
00879
00880 if(mBeamLineTracks) {
00881 StIOMaker *ioMk=(StIOMaker*)StMaker::GetChain()->GetMaker("inputStream");
00882
00883 TString tt="ppv";
00884 if(ioMk) {
00885 assert(ioMk);
00886 const char *fname=ioMk->GetFileName();
00887 tt=strstr(fname,"st_");
00888 tt.ReplaceAll(".daq",".ppv");
00889 } else {
00890 tt= ((StBFChain*)StMaker::GetChain())->GetFileOut() ;
00891 tt.ReplaceAll(".root",".ppv");
00892 }
00893 LOG_INFO << "PPV save local histo="<<tt<<endm;
00894 saveHisto(tt.Data());
00895 }
00896
00897 LOG_INFO << "StPPVertexFinder::Finish() done, seen eve=" <<mTotEve<< endm;
00898
00899
00900 }
00901
00902
00903
00904 void
00905 StPPVertexFinder::saveHisto(TString fname){
00906 TString outName=fname+".hist.root";
00907 TFile f( outName,"recreate");
00908 assert(f.IsOpen());
00909 printf("%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
00910 HList->ls();
00911 HList->Write();
00912 f.Close();
00913 }
00914
00915
00916
00917 void
00918 StPPVertexFinder::dumpKalmanNodes(const StiKalmanTrack*track){
00919
00920
00921 StiKTNBidirectionalIterator it;
00922 int in=0,nh=0,nTpc=0;
00923 float zL=999, zH=-999;
00924 for (it=track->begin();it!=track->end();it++,in++) {
00925 StiKalmanTrackNode& ktn = (*it);
00926 if(!ktn.isValid()) continue;
00927 if(ktn.getHit() && ktn.getChi2() >1000) continue;
00928 const StiDetector * det=ktn.getDetector();
00929 assert(!(ktn.x()) || det);
00930 float rxy=ktn.getX();
00931 bool actv= !det || det->isActive(ktn.getY(), ktn.getZ());
00932 if(!det || (rxy>58 && rxy < 190)){
00933 float z=ktn.z_g();
00934 if(zL>z) zL=z;
00935 if(zH<z) zH=z;
00936 if(actv) {
00937 nTpc++;
00938 if(ktn.getHit()) nh++;
00939 }
00940 }
00941 }
00942 int nn=in;
00943 TString tagPlp=" "; if((nTpc-nh)>10) tagPlp=" plp";
00944 TString tagMemb=" "; if(zH*zL<0) tagMemb=" memb";
00945
00946 cout <<"\n#e dumpKalmanNodes nNodes="<<nn<<" actv: nTPC="<<nTpc<<" nHit="<<nh
00947 <<" zL="<<zL<<" zH="<<zH <<tagPlp<<tagMemb
00948 <<endl;
00949
00950
00951 cout <<"#e |P|="<<track->getP()<<" pT="<<track->getPt()<<" eta="<<track->getPseudoRapidity()<<" nFitP="<<track->getFitPointCount()<<endl;
00952 StiKalmanTrackNode* inNode=track->getInnerMostNode();
00953 cout<<"#e @InnerMostNode x:"<< inNode->x_g()<<" y:"<< inNode->y_g()<<" z:"<< inNode->z_g()<<" Eta="<<inNode->getEta()<<" |P|="<<inNode->getP()<<endl;
00954 StiKalmanTrackNode* ouNode=track->getOuterMostNode();
00955 cout<<"#e @OuterMostNode g x:"<< ouNode->x_g()<<" y:"<< ouNode->y_g()<<" z:"<< ouNode->z_g()<<" Eta="<<ouNode->getEta()<<" |P|="<<ouNode->getP()<<endl;
00956
00957 in=0;
00958 for (it=track->begin();it!=track->end();it++,in++) {
00959
00960 StiKalmanTrackNode& ktn = (*it);
00961 if(!ktn.isValid()) continue;
00962 if(ktn.getHit() && ktn.getChi2() >1000) continue;
00963 float sy=sqrt(ktn.getCyy());
00964 float sz=sqrt(ktn.getCzz());
00965 const StiDetector * det=ktn.getDetector();
00966 assert(!(ktn.x()) || det);
00967 cout<<"#e in="<<in<<" |P|="<<ktn.getP()<<" Local: x="<<ktn.getX()<<" y="<<ktn.getY()<<" +/- "<<sy<<" z="<<ktn.getZ()<<" +/- "<<sz;
00968 if(ktn.getHit()) cout <<" hit=1";
00969 else cout <<" hit=0";
00970 if(det==0) cout<<" noDet ";
00971 else cout<<" detActv="<<(!det || det->isActive(ktn.getY(), ktn.getZ()));
00972 cout <<endl;
00973
00974 }
00975 }
00976
00977
00978
00979 bool
00980 StPPVertexFinder::examinTrackDca(const StiKalmanTrack*track,TrackData &t){
00981
00982
00983
00984
00985
00986 StiKalmanTrack track1=*track;
00987 StiKalmanTrackNode* bmNode=track1.extrapolateToBeam();
00988 if(bmNode==0) {
00989
00990 return false ;
00991 }
00992
00993 float rxy=rxyG(bmNode);
00994
00995
00996 if(rxy>mMaxTrkDcaRxy) return false;
00997 if( fabs(bmNode->z_g())> mMaxZrange ) return false ;
00998
00999
01000
01001 t.zDca=zL(bmNode);
01002 t.ezDca=ezL(bmNode);
01003 t.rxyDca=rxy;
01004 t.gPt=bmNode->getPt();
01005
01006
01007 t.dcaTrack.R.SetXYZ(xG(bmNode),yG(bmNode),zG(bmNode));
01008
01009 t.dcaTrack.sigYloc=eyL(bmNode);
01010 t.dcaTrack.sigZ=ezL(bmNode);
01011 StThreeVectorF const globP3=bmNode->getGlobalMomentumF();
01012 t.dcaTrack.gP.SetXYZ(globP3.x(),globP3.y(),globP3.z());
01013 t.dcaTrack.fitErr=bmNode->fitErrs();
01014 t.dcaTrack.gChi2=track1.getChi2();
01015 t.dcaTrack.nFitPoint=track1.getFitPointCount();
01016
01017
01018 return true;
01019 }
01020
01021
01022
01023
01024 void
01025 StPPVertexFinder::matchTrack2BTOF(const StiKalmanTrack* track,TrackData &t,StBTofGeometry* geom){
01026
01027 StiKalmanTrackNode* ouNode=track->getOuterMostNode();
01028
01029 StThreeVectorD posTOF;
01030
01031 StThreeVectorD ou(ouNode->getX(),ouNode->getY(),ouNode->getZ());
01032 ou.rotateZ(ouNode->getAlpha());
01033 StPhysicalHelixD hlx(fabs(ouNode->getCurvature()),
01034 ouNode->getDipAngle(),
01035 ouNode->getPhase(),
01036 ou,
01037 ouNode->getHelicity());
01038 IntVec idVec;
01039 DoubleVec pathVec;
01040 PointVec crossVec;
01041
01042 IntVec iBinVec;
01043 if(geom->HelixCrossCellIds(hlx,idVec,pathVec,crossVec)) {
01044 for(size_t i=0;i<idVec.size();i++) {
01045 int itray, imodule, icell;
01046 geom->DecodeCellId(idVec[i], icell, imodule, itray);
01047
01048 Double_t local[3], global[3];
01049 for(int j=0;j<3;j++) local[j] = 0;
01050 global[0] = crossVec[i].x();
01051 global[1] = crossVec[i].y();
01052 global[2] = crossVec[i].z();
01053 StBTofGeomSensor *sensor = geom->GetGeomSensor(imodule,itray);
01054 if(!sensor) {
01055 LOG_WARN << "no sensitive module in this projection??? - weird" << endm;
01056 continue;
01057 }
01058 sensor->Master2Local(&global[0],&local[0]);
01059
01060
01061
01062
01063
01064 if(local[2]<mMinZBtof||local[2]>mMaxZBtof) continue;
01065 int iBin = btofList->cell2bin(itray, imodule, icell);
01066 iBinVec.push_back(iBin);
01067 btofList->addBtofTrack(itray, imodule, icell);
01068 LOG_DEBUG << " !!! Push to the list ...tray/module/cell " << itray << "/" << imodule << "/" << icell << endm;
01069 }
01070 }
01071
01072 bool btofMatch=btofList->isMatched(iBinVec);
01073 bool btofVeto =btofList->isVetoed(iBinVec);
01074 float btofW =btofList->getWeight(iBinVec);
01075 btofList->addBtofMatch(iBinVec);
01076
01077 LOG_DEBUG << " ** BTOF ** match/veto/weight = " << btofMatch << " " << btofVeto << " " << btofW << endm;
01078
01079 t.updateAnyMatch(btofMatch,btofVeto,t.mBtof);
01080 t.weight*=btofW;
01081 t.btofBin= iBinVec.size() ? iBinVec[0] : -1;
01082 }
01083
01084
01085
01086 void
01087 StPPVertexFinder::matchTrack2CTB(const StiKalmanTrack* track,TrackData &t){
01088 const double Rctb=213.6;
01089
01090 StiKalmanTrackNode* ouNode=track->getOuterMostNode();
01091
01092 StThreeVectorD posCTB;
01093 float path=-1;
01094
01095 if(1){
01096 StiKalmanTrackNode * inNode = ouNode;
01097 StThreeVectorD in(inNode->getX(),inNode->getY(),inNode->getZ());
01098 in.rotateZ(inNode->getAlpha());
01099 StPhysicalHelixD hlx(fabs(inNode->getCurvature()),
01100 inNode->getDipAngle(),
01101 inNode->getPhase(),
01102 in,
01103 inNode->getHelicity());
01104 pairD d2;
01105 d2 = hlx.pathLength(Rctb);
01106 path=d2.second;
01107 if(d2.first>=0 || d2.second<=0) {
01108 LOG_DEBUG <<Form("WARN MatchTrk , unexpected solution for track crossing CTB\n")<<
01109 Form(" d2.firts=%f, second=%f, try first", d2.first, d2.second)<<endm;
01110 path=d2.first;
01111 }
01112 posCTB = hlx.at(path);
01113
01114 }
01115
01116
01117 if(0){
01118 StiKalmanTrack track2=*track;
01119 StiKalmanTrackNode* ctbNode=track2.extrapolateToRadius(Rctb);
01120
01121 if(ctbNode==0) {
01122 cout<<"#e @ctbNode NULL"<<endl;
01123 cout<<"#e @track dump"<< *track;
01124 cout<<"#e @OuterMostNode dump"<< *ouNode <<endl;
01125 return;
01126 }
01127
01128
01129
01130 posCTB=StThreeVectorD( ctbNode->x_g(),ctbNode->y_g(),ctbNode->z_g());
01131 }
01132
01133 float phi=atan2(posCTB.y(),posCTB.x());
01134 if(phi<0) phi+=2*C_PI;
01135 float eta=posCTB.pseudoRapidity();
01136
01137 if(fabs(eta)<1) hA[10]->Fill(posCTB.z());
01138
01139 int iBin=ctbList->addTrack(eta,phi);
01140
01141 bool ctbMatch=ctbList->isMatched(iBin);
01142 bool ctbVeto =ctbList->isVetoed(iBin);
01143 float ctbW =ctbList->getWeight(iBin);
01144
01145 t.updateAnyMatch(ctbMatch,ctbVeto,t.mCtb);
01146 t.weight*=ctbW;
01147 t.ctbBin=iBin;
01148 }
01149
01150
01151
01152 void
01153 StPPVertexFinder::matchTrack2BEMC(const StiKalmanTrack* track,TrackData &t, float Rxy){
01154
01155 StiKalmanTrackNode* ouNode=track->getOuterMostNode();
01156
01157 StThreeVectorD posCyl;
01158 float path=-1;
01159
01160 StThreeVectorD ou(ouNode->getX(),ouNode->getY(),ouNode->getZ());
01161 ou.rotateZ(ouNode->getAlpha());
01162 StPhysicalHelixD hlx(fabs(ouNode->getCurvature()),
01163 ouNode->getDipAngle(),
01164 ouNode->getPhase(),
01165 ou,
01166 ouNode->getHelicity());
01167 pairD d2;
01168 d2 = hlx.pathLength(Rxy);
01169 path=d2.second;
01170 if(d2.first>=0 || d2.second<=0) {
01171 LOG_DEBUG <<Form("WARN MatchTrk , unexpected solution for track crossing BEMC Cyl\n")<<
01172 Form(" d2.firts=%f, second=%f, try first\n", d2.first, d2.second)<<endm;
01173 path=d2.first;
01174 }
01175 posCyl = hlx.at(path);
01176
01177
01178
01179 float phi=atan2(posCyl.y(),posCyl.x());
01180 if(phi<0) phi+=2*C_PI;
01181 float eta=posCyl.pseudoRapidity();
01182
01183
01184
01185 if(fabs(eta)<1) hA[11]->Fill(posCyl.z());
01186
01187 int iBin=bemcList->addTrack(eta,phi);
01188 bool bemcMatch=bemcList->isMatched(iBin);
01189 bool bemcVeto =bemcList->isVetoed(iBin);
01190 float bemcW =bemcList->getWeight(iBin);
01191
01192 t.updateAnyMatch(bemcMatch,bemcVeto,t.mBemc);
01193 t.weight*=bemcW;
01194 t.bemcBin=iBin;
01195
01196 }
01197
01198
01199
01200
01201 void
01202 StPPVertexFinder::matchTrack2EEMC(const StiKalmanTrack* track,TrackData &t,float z){
01203
01204 const float minEta=0.7 ;
01205 const float maxPath=200 ;
01206
01207 StiKalmanTrackNode* ouNode=track->getOuterMostNode();
01208 StiKalmanTrackNode* inNode=track->getInnerMostNode();
01209
01210
01211 if(inNode->getZ()> ouNode->getZ()) return;
01212
01213
01214 if(track->getPseudoRapidity()<minEta) return;
01215
01216 StThreeVectorD rSmd=StThreeVectorD(0,0,z);
01217 StThreeVectorD n=StThreeVectorD(0,0,1);
01218
01219 StThreeVectorD ou(ouNode->getX(),ouNode->getY(),ouNode->getZ());
01220 ou.rotateZ(ouNode->getAlpha());
01221 StPhysicalHelixD hlx(fabs(ouNode->getCurvature()),
01222 ouNode->getDipAngle(),ouNode->getPhase(),
01223 ou,ouNode->getHelicity());
01224
01225
01226
01227
01228
01229 double path = hlx.pathLength(rSmd,n);
01230
01231 if(path>maxPath) return;
01232
01233 StThreeVectorD r = hlx.at(path);
01234 float periodL=hlx. period();
01235
01236 if(periodL<2*path) {
01237 LOG_DEBUG <<Form(" Warn, long path fac=%.1f ",path/periodL)<<
01238 Form(" punchEEMC1 x,y,z=%.1f, %.1f, %.1f path=%.1f period=%.1f\n",r.x(),r.y(),r.z(),path,periodL)<<endm;
01239 }
01240
01241 float phi=atan2(r.y(),r.x());
01242 if(phi<0) phi+=2*C_PI;
01243 float eta=r.pseudoRapidity();
01244
01245 int iBin=eemcList->addTrack(eta,phi);
01246 bool eemcMatch=eemcList->isMatched(iBin);
01247 bool eemcVeto =eemcList->isVetoed(iBin);
01248 float eemcW =eemcList->getWeight(iBin);
01249
01250 t.updateAnyMatch(eemcMatch,eemcVeto,t.mEemc);
01251 t.weight*=eemcW;
01252 t.eemcBin=iBin;
01253
01254 }
01255
01256
01257
01258 bool
01259 StPPVertexFinder::matchTrack2Membrane(const StiKalmanTrack* track,TrackData &t){
01260 const float RxyMin=59, RxyMax=199, zMax=200;
01261 const float zMembraneDepth=1;
01262
01263
01264 vector<int> hitPatt;
01265 int nPos=0,nFit=0;
01266 int in=0;
01267 float lastRxy=9999;
01268 float lastZ=9999;
01269
01270 int jz0=0;
01271 StiKTNBidirectionalIterator it;
01272 for (it=track->begin();it!=track->end();it++) {
01273 StiKalmanTrackNode* ktnp=& (*it);
01274 if(!ktnp->isValid()) continue;
01275
01276 float rxy=rxyG(ktnp);
01277 float z=zG(ktnp);
01278 if(rxy<RxyMin) continue;
01279 if(rxy>RxyMax) continue;
01280 if(fabs(z)>zMax) continue;
01281
01282 if(lastRxy<=rxy){
01283 LOG_WARN << "StPPVertexFinder::matchTrack2Membrane() \n the "<<in<<" node of the kalmanTrack below is out of order and is ignorred in (some) of vertex finder analysis"<<"\n Z="<<z<<" rXY="<<rxy<<" last_rxy="<<lastRxy<<endm;
01284
01285 continue;
01286 }
01287 lastRxy=rxy;
01288 if(in==0) lastZ=z;
01289 in++;
01290 if(fabsf(z)>zMembraneDepth) {
01291 if(lastZ*z<0) {
01292 if(jz0>0) {
01293 LOG_WARN << "StPPVertexFinder::matchTrack2Membrane() \n the "<<in<<" node of the kalmanTrack crosses Z=0 for the 2nd time, this track has a strange list of nodes - continue"<<endm;
01294
01295 }
01296
01297 jz0=hitPatt.size();
01298 }
01299 lastZ=z;
01300 }
01301 const StiDetector * det=ktnp->getDetector();
01302 assert(!(ktnp->x()) || det);
01303 bool active=!det || det->isActive(yL(ktnp), zL(ktnp));
01304 int hit=ktnp->getHit()?1:0;
01305 if(active) {
01306 hitPatt.push_back(hit);
01307 nPos++;
01308 if(hit && ktnp->getChi2() <=1000 ) nFit++;
01309 }
01310
01311 }
01312
01313
01314 if(nFit< mMinFitPfrac * nPos) return false;
01315 t.scanNodes(hitPatt,jz0);
01316 return true;
01317 }
01318
01319
01320
01321
01322 bool StPPVertexFinder::isPostCrossingTrack(const StiKalmanTrack* track){
01323 const float RxyMin=59, RxyMax=199, zMax=200;
01324 const float zMembraneDepth=1.0;
01325 const int nWrongZHitCut=2;
01326 int nWrongZHit=0;
01327 StiKTNBidirectionalIterator it;
01328 for (it=track->begin();it!=track->end();it++) {
01329 StiKalmanTrackNode* ktnp=& (*it);
01330 if(!ktnp->isValid() || ktnp->getChi2()>1000 ) continue;
01331 StiHit* stihit=ktnp->getHit();
01332 if(stihit){
01333 StHit* sthit=(StHit*)stihit->stHit();
01334 if(sthit){
01335 if(sthit->detector()==kTpcId){
01336 StTpcHit* hit=(StTpcHit*) sthit;
01337 float r=hit->position().perp();
01338 if (r < RxyMin) continue;
01339 if (r > RxyMax) continue;
01340 float z=hit->position().z();
01341 if (fabs(z) > zMax) continue;
01342 if ((z < -zMembraneDepth && hit->sector() <= 12) ||
01343 (z > zMembraneDepth && hit->sector() > 12)) {
01344 nWrongZHit++;
01345 if(nWrongZHit>=nWrongZHitCut) {return true;}
01346 }
01347 }
01348 }
01349 }
01350 }
01351 return false;
01352 }
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506 #if 0
01507
01508 old scraps of code
01509
01510 ---------------------------
01511 const float maxZerr=1;
01512
01513 fprintf(fdOut,"%3d nEve %.2f %d %d %d %d %d %d %d ",mTotEve,zGeant,ctbList->getnFired(),bemcList->getnFired(),eemcList->getnFired(),mTrackData->size(),nTpcM,nTpcV,mVertexData->size());
01514 if(mVertexData->size()>1)
01515 fprintf(fdOut,"nV ");
01516 else
01517 fprintf(fdOut,"nv ");
01518 fprintf(fdOut," %d\n",eveID);
01519
01520 float del=888;
01521 for(i=0;i<mVertexData->size();i++) {
01522 VertexData *V=&mVertexData->at(i);
01523 printf("%.1f:%d:%d ",V->r.z(),V->nUsedTrack,V->nAnyMatch);
01524 fprintf(fdOut," v %d %.2f %d %d %d %d %d %d %d %d %d %d %d",i+1,V->r.z(),V->nUsedTrack,V->nAnyMatch,V->nAnyVeto,V->nCtb,V->nCtbV,V->nBemc,V->nBemcV,V->nEemc,V->nEemcV,V->nTpc,V->nTpcV);
01525
01526 if(fabs(V->r.z()-zGeant)<maxZerr) {
01527 printf("****%d ",i+1);
01528 fprintf(fdOut," *\n");
01529 del=zGeant-V->r.z();
01530 hA[13]->Fill(del);
01531 } else
01532 fprintf(fdOut," ,\n");
01533
01534 }
01535 printf(" del=%.1f\n",del);
01536
01537
01538 ===============================================================
01539
01540 int PlotEveN=-1;
01541
01542 if(mTotEve==PlotEveN )
01543 plotVertex(&V);
01544 }
01545 if(mTotEve==PlotEveN ) plotTracksDca() ;
01546
01547
01548
01549
01550 void StPPVertexFinder::plotVertex(VertexData *V) {
01551 float z0=V->r.z();
01552 float ez=V->er.z();
01553 TH1D *h=( TH1D *) hL->Clone();
01554 char txt[100];
01555 sprintf(txt,"e%dV%d",mTotEve,V->id);
01556 h->SetName(txt);
01557 sprintf(txt,"lnLike vertZ=%d nTr=%d eveID=%d",V->id,V->nUsedTrack,eveID);
01558 h->SetTitle(txt);
01559 h->SetAxisRange(z0-8, z0+8);
01560 HList->Add(h);
01561
01562 TList* LL= h->GetListOfFunctions();
01563
01564
01565 sprintf(txt,"e%dV%dL",mTotEve,V->id);
01566 TF1 *fL = new TF1(txt,"[2]- (x-[0])*(x-[0])/2/[1]/[1]",-200,200);
01567 fL->SetParName(0,"z0");
01568 fL->SetParName(1,"sig");
01569 fL->SetParName(2,"Lmax");
01570 fL->SetLineColor(kRed);
01571 fL->SetLineWidth(1);
01572 fL->SetParameter(0,z0);
01573 fL->SetParameter(1,ez);
01574 fL->SetParameter(2,V->Lmax);
01575 LL->Add(fL);
01576 TLine *ln=new TLine(z0,0,z0,V->Lmax); ln->SetLineColor(kRed);
01577 LL->Add(ln);
01578 ln=new TLine(z0+ez,0,z0+ez,V->Lmax); ln->SetLineColor(kRed);
01579 ln->SetLineStyle(2); LL->Add(ln);
01580 ln=new TLine(z0-ez,0,z0-ez,V->Lmax); ln->SetLineColor(kRed);
01581 ln->SetLineStyle(2); LL->Add(ln);
01582 }
01583
01584
01585
01586 void StPPVertexFinder::plotTracksDca() {
01587 #if 0
01588 char txt[100];
01589
01590 sprintf(txt,"e%dGin",mTotEve);
01591 TGraphErrors *g1=new TGraphErrors;
01592 g1->SetMarkerStyle(27);
01593 g1->SetName(txt);
01594 sprintf(txt,"in-time Z along beam @ DCA, eveID=%d; Z (cm); pT (GeV/c)",eveID);
01595 g1->SetTitle(txt);
01596 g1->SetLineColor(kBlue);
01597 g1->SetMarkerColor(kBlue);
01598
01599 sprintf(txt,"e%dGout",mTotEve);
01600 TGraphErrors *g2=new TGraphErrors;
01601 g2->SetMarkerStyle(5);
01602 g2->SetName(txt);
01603 sprintf(txt,"out-of-time Z along beam @ DCA, eveID=%d; Z (cm); pT (GeV/c)",eveID);
01604 g2->SetTitle(txt);
01605 g2->SetLineColor(kMagenta);
01606 g2->SetMarkerColor(kMagenta);
01607
01608 int i;
01609 int nt=mTrackData->size();
01610 for(i=0;i<nt;i++) {
01611 TrackData *t=&mTrackData->at(i);
01612 TGraphErrors *g=g1;
01613 if(!t->ctbMatch) g=g2;
01614 int n=g->GetN();
01615 g->SetPoint(n,t->zDca,t->gPt);
01616 g->SetPointError(n,t->ezDca,0);
01617 }
01618 HList->Add(g1);
01619 HList->Add(g2);
01620 #endif
01621 }
01622
01623
01624 #endif