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
00030
#include <Stiostream.h>
00031
#include <stdlib.h>
00032
#include <string.h>
00033
#include <math.h>
00034
#include <vector>
00035
#include "MatchedTrk.h"
00036
#include "tables/St_g2t_ctf_hit_Table.h"
00037
#include "tables/St_g2t_vertex_Table.h"
00038
#include "tables/St_g2t_track_Table.h"
00039
00040
#include "TH2.h"
00041
void cts_get_ctb_indexes (
long volume,
long &i_phi,
long &i_eta ) ;
00042
00043
#include "StVertexMaker.h"
00044
00045
#include "SystemOfUnits.h"
00046
#if !defined(ST_NO_NAMESPACES)
00047
using namespace std;
00048
using namespace units;
00049
#endif
00050
#include "StThreeVectorD.hh"
00051
#include "StHelixD.hh"
00052
#include "StPhysicalHelixD.hh"
00053
#include "TMath.h"
00054
#include "tables/St_dst_track_Table.h"
00055
#include "tables/St_dst_vertex_Table.h"
00056
#include "StDetectorDefinitions.h"
00057
00058
#include "Stypes.h"
00059
00060
#include "StVertexId.h"
00061
#include "math_constants.h"
00062
00063
#include "StarCallf77.h"
00064
extern "C" {
void type_of_call F77_NAME(gufld,GUFLD)(
float *x,
float *b);}
00065
#define gufld F77_NAME(gufld,GUFLD)
00066
00067
00068
00069
struct Jcyl {
float eta,phi;};
00070
00071
00072
00073
00074
long StVertexMaker::ppLMV4(MatchedTrk &maTrk,St_dst_track *trackAll, St_dst_vertex *vertex, Int_t mdate )
00075 {
00076 uint mMinMatchTr=ppLMVparI[3];
00077
if(beam4ppLMV.isOn)mMinMatchTr++;
00078
00079
00080
00081
int bXing=trigBXing;
00082 LOG_INFO<< Form(
" THIS IS ppLMV -START, use only tracks matched to CTB in bXing=%d\n",bXing+firstBXing)<<endm;
00083
00084
if(bXing<0)
00085 {LOG_INFO<< Form(
"No tracks matched to selected bXing=%d",bXing)<<endm;
return kStOk;}
00086
00087 vector <Jtrk> *tracks=&(maTrk.tracks[bXing]);
00088
00089 LOG_INFO<< Form(
"passed tracks match to CTB nTracks=%d, BeamLine=%d\n",(*tracks).size(), beam4ppLMV.isOn)<<endm;
00090
00091
00092
00093
float x[3] = {0,0,0};
00094
float b[3];
00095 gufld(x,b);
00096
double bfield = 0.1*b[2];
00097
if(fabs(bfield)<0.0001) bfield=0.00222;
00098
00099
00100
if( beam4ppLMV.isOn) {
00101
00102
if (! (beam4ppLMV.equivNtr>0))
return kStErr;
00103
double pt = 88889999;
00104
double nxy=::sqrt(beam4ppLMV.nx*beam4ppLMV.nx +beam4ppLMV.ny*beam4ppLMV.ny);
00105
if(nxy<1.e-5){
00106 nxy=beam4ppLMV.nx=1.e-5;
00107 }
00108
double p0=pt/nxy;
00109
double px = p0*beam4ppLMV.nx;
00110
double py = p0*beam4ppLMV.ny;
00111
double pz = p0;
00112 StThreeVectorD MomFstPt(px*GeV, py*GeV, pz*GeV);
00113 StThreeVectorD origin(beam4ppLMV.x0, beam4ppLMV.y0, 0.);
00114
00115
struct Jtrk trk1;
00116 trk1.glb_track_pointer=0;
00117 trk1.helix=StPhysicalHelixD (MomFstPt, origin, bfield*tesla, 1.);
00118
00119
float sigMin=100000;
00120
for( uint j=0;j<(*tracks).size();j++) {
00121
float sig=(*tracks)[j].sigma;
00122
if(sigMin>sig) sigMin=sig;
00123 }
00124
00125 trk1.sigma=sigMin/::sqrt(beam4ppLMV.equivNtr);
00126 (*tracks).push_back(trk1);
00127 LOG_WARN<< Form(
"WARN ppLMV: nominal beam line added with sigma=%f, now nTrack=%d beamLineX=%f, Y=%f Weight=%d\n", trk1.sigma,(*tracks).size(),beam4ppLMV.x0,beam4ppLMV.y0,beam4ppLMV.equivNtr)<<endm;
00128
00129 }
00130
00131
static int eveId=0;
00132 eveId++;
00133
00134
00135
double DVtxMax = 4.0;
00136
00137
00138
long Is_SVT = 0;
00139
if( mdate > 20000700 )Is_SVT=1;
00140
00141
00142
00143
00144
00145
00146
double xo=0.0,yo=0.0;
00147
if( beam4ppLMV.equivNtr>0) {
00148 xo=beam4ppLMV.x0;
00149 yo=beam4ppLMV.y0;
00150 }
00151
00152
00153
double A11=0.0,A12=0.0,A13=0.0,A21=0.0,A22=0.0,A23=0.0;
00154
double A31=0.0,A32=0.0,A33=0.0;
00155
double C11=0.0,C12=0.0,C13=0.0,C21=0.0,C22=0.0,C23=0.0;
00156
double C31=0.0,C32=0.0,C33=0.0;
00157
int done = 0;
00158
double chi2=0;
00159 StThreeVectorD XVertex(999.,888.,777.);
00160
while( done != 1 ){
00161
00162
00163
if( (*tracks).size() <= 1 ){
00164 cout<<
"ppLMV: Fewer than 2 track remains. No vertex found."<<endl;
00165
return kStWarn;
00166 }
00167
00168
00169 A11=0.0,A12=0.0,A13=0.0,A21=0.0,A22=0.0,A23=0.0;
00170 A31=0.0,A32=0.0,A33=0.0;
00171 C11=0.0,C12=0.0,C13=0.0,C21=0.0,C22=0.0,C23=0.0;
00172 C31=0.0,C32=0.0,C33=0.0;
00173
double b1=0.0,b2=0.0,b3=0.0;
00174
00175
for(
unsigned int itr=0; itr < (*tracks).size(); itr++){
00176
00177
double spath = (*tracks)[itr].helix.pathLength(xo,yo);
00178 StThreeVectorD XClosest = (*tracks)[itr].helix.at(spath);
00179 StThreeVectorD XMomAtClosest = (*tracks)[itr].helix.momentumAt(spath,bfield*tesla);
00180
double xp = XClosest.x();
double yp= XClosest.y();
double zp= XClosest.z();
00181
00182
00183
double xhat = XMomAtClosest.x()/XMomAtClosest.mag();
00184
double yhat = XMomAtClosest.y()/XMomAtClosest.mag();
00185
double zhat = XMomAtClosest.z()/XMomAtClosest.mag();
00186 A11=A11+(yhat*yhat+zhat*zhat)/(*tracks)[itr].sigma;
00187 A12=A12-(xhat*yhat)/(*tracks)[itr].sigma;
00188 A13=A13-(xhat*zhat)/(*tracks)[itr].sigma;
00189 A22=A22+(xhat*xhat+zhat*zhat)/(*tracks)[itr].sigma;
00190 A23=A23-(yhat*zhat)/(*tracks)[itr].sigma;
00191 A33=A33+(xhat*xhat+yhat*yhat)/(*tracks)[itr].sigma;
00192 b1=b1 + ( (yhat*yhat+zhat*zhat)*xp - xhat*yhat*yp - xhat*zhat*zp )/(*tracks)[itr].sigma;
00193 b2=b2 + ( (xhat*xhat+zhat*zhat)*yp - xhat*yhat*xp - yhat*zhat*zp )/(*tracks)[itr].sigma;
00194 b3=b3 + ( (xhat*xhat+yhat*yhat)*zp - xhat*zhat*xp - yhat*zhat*yp )/(*tracks)[itr].sigma;
00195 }
00196 A21 = A12; A31=A13; A32=A23;
00197
00198
00199
double detA = A11*A22*A33 + A12*A23*A31 + A13*A21*A32;
00200 detA = detA - A31*A22*A13 - A32*A23*A11 - A33*A21*A12;
00201
00202
00203
00204
00205
00206 C11=(A22*A33-A23*A32)/detA; C12=(A13*A32-A12*A33)/detA; C13=(A12*A23-A13*A22)/detA;
00207 C21=C12; C22=(A11*A33-A13*A31)/detA; C23=(A13*A21-A11*A23)/detA;
00208 C31=C13; C32=C23; C33=(A11*A22-A12*A21)/detA;
00209
00210
00211
double Xv = C11*b1 + C12*b2 + C13*b3;
00212
double Yv = C21*b1 + C22*b2 + C23*b3;
00213
double Zv = C31*b1 + C32*b2 + C33*b3;
00214 XVertex.setX(Xv); XVertex.setY(Yv); XVertex.setZ(Zv);
00215
00216
00217
00218
00219
00220
00221
00222
#ifdef ST_NO_TEMPLATE_DEF_ARGS
00223
wrong lines
00224 vector<StPhysicalHelixD,allocator<StPhysicalHelixD> >::iterator itehlx=(*tracks).helix.begin(), i1keep;
00225 vector<double,allocator<double> >::iterator itesig=sigma.begin(),i2keep;
00226 vector<long,allocator<long> >::iterator iteind=index.begin(),i3keep;
00227
#else
00228
vector<Jtrk >::iterator itehlx=(*tracks).begin(), i1keep;
00229
#endif
00230
00231
double dmax=0.0;
00232
while(itehlx != (*tracks).end()){
00233
if( (*itehlx).glb_track_pointer==0) {itehlx++;
continue;}
00234 StPhysicalHelixD hlx = (*itehlx).helix;
00235
double sig = (*itehlx).sigma;
00236
double spath = hlx.pathLength(XVertex.x(),XVertex.y());
00237 StThreeVectorD XHel = hlx.at(spath);
00238
double d=(XHel.x()-XVertex.x())*(XHel.x()-XVertex.x());
00239 d = d+(XHel.y()-XVertex.y())*(XHel.y()-XVertex.y());
00240 d = d+(XHel.z()-XVertex.z())*(XHel.z()-XVertex.z());
00241 d = ::sqrt(d);
00242 chi2 = chi2 + (d*d)/(sig*sig);
00243
double drel = d;
00244
00245
if( drel > dmax ){
00246
00247 dmax = drel;
00248 i1keep = itehlx;
00249 }
00250
00251 itehlx++;
00252 }
00253
00254
if( dmax > DVtxMax ){
00255
00256 (*tracks).erase(i1keep);
00257 done=0;
00258 }
00259
else{
00260 done=1;
00261 }
00262 }
00263
00264
double chi2pdof = chi2/((*tracks).size()-1);
00265
00266
00267 cout<<
"ppLMV: Primary Vertex found! Position: "<<XVertex<<
", used tracks="<<(*tracks).size()<<endl;
00268
if ((*tracks).size()< mMinMatchTr){
00269 gMessMgr->
Warning() <<
"ppLMV ended, only "<<(*tracks).size()<<
"tracks - too few, abort this vertex, quit ppLMV" << endm;
00270
return kStWarn;
00271 }
00272
00273
00274 Int_t nrows = vertex->GetNRows();
00275
long IVertex = nrows+1;
00276
00277
00278 dst_vertex_st primvtx;
00279 primvtx.vtx_id = kEventVtxId;
00280 primvtx.n_daughters = (*tracks).size();
00281 primvtx.id = IVertex;
00282 primvtx.iflag = 1;
00283
if( (Is_SVT == 1) ){
00284 primvtx.det_id = kTpcSsdSvtIdentifier;
00285 }
00286
else{
00287 primvtx.det_id = kTpcIdentifier;
00288 }
00289 primvtx.id_aux_ent = 0;
00290 primvtx.x = XVertex.x();
00291 primvtx.y = XVertex.y();
00292 primvtx.z = XVertex.z();
00293 primvtx.covar[0] = C11;
00294 primvtx.covar[1] = C12;
00295 primvtx.covar[2] = C22;
00296 primvtx.covar[3] = C13;
00297 primvtx.covar[4] = C23;
00298 primvtx.covar[5] = C33;
00299 primvtx.chisq[0] = chi2pdof;
00300 primvtx.chisq[1] = 1.0;
00301 vertex->AddAt(&primvtx,nrows);
00302
00303
00304 dst_track_st *sec_pointer = trackAll->GetTable();
00305
for (
long ll=0; ll<trackAll->GetNRows(); ll++){
00306
long idt = sec_pointer->id;
00307
long icheck;
00308 icheck = 0;
00309
for(
unsigned int ine=0; ine < (*tracks).size(); ine++){
00310
if((*tracks)[ine].glb_track_pointer==0)
continue;
00311
if( idt == (*tracks)[ine].glb_track_pointer->id )icheck=1;
00312 }
00313 Int_t istart_old;
00314
if( icheck == 1 ){
00315
00316 istart_old = sec_pointer->id_start_vertex;
00317 sec_pointer->id_start_vertex = 10*IVertex + istart_old;
00318 }
00319 sec_pointer++;
00320 }
00321
00322
00323
00324
for(uint j=0;j<maTrk.primCan.size(); j++) {
00325
00326
if(maTrk.primCan[j].glb_track_pointer->id_start_vertex>=10)
continue;
00327
double dz=maTrk.primCan[j].z0 - XVertex.z();
00328
if(fabs(dz)>DVtxMax)
continue;
00329
double dx=maTrk.primCan[j].x0 - XVertex.x();
00330
double dy=maTrk.primCan[j].y0 - XVertex.y();
00331
double dr2=dx*dx + dy*dy + dz*dz;
00332
double dr=::sqrt(dr2);
00333
if(dr>DVtxMax)
continue;
00334 maTrk.primCan[j].glb_track_pointer->id_start_vertex+=10*IVertex ;
00335 }
00336
00337 {
00338 hPiFi[13]->Fill((*tracks).size());
00339
for(uint j=0;j<(*tracks).size();j++) {
00340
if((*tracks)[j].glb_track_pointer==0)
continue;
00341
float pt=1./(*tracks)[j].glb_track_pointer->invpt;
00342
int npoint=(*tracks)[j].glb_track_pointer->n_point;
00343 hPiFi[14]->Fill(pt);
00344 hPiFi[15]->Fill(npoint);
00345 }
00346
00347
float rXver=XVertex.x();
00348
float rYver=XVertex.y();
00349
float rZver=XVertex.z();
00350
00351 ((TH2F*)hPiFi[6])->Fill(rXver,rYver);
00352 hPiFi[7]->Fill(rXver);
00353 hPiFi[8]->Fill(rYver);
00354 hPiFi[9]->Fill(rZver);
00355 ((TH2F*)hPiFi[16])->Fill(rZver,rXver);
00356 ((TH2F*)hPiFi[17])->Fill(rZver,rYver);
00357
00358
00359 g2t_vertex_st *GVER=(g2t_vertex_st *)maTrk.GVER[bXing];
00360
00361
if(GVER) {
00362 hPiFi[10]->Fill(GVER->ge_x[2]-rZver);
00363 hPiFi[11]->Fill(GVER->ge_x[0]-rXver);
00364 hPiFi[12]->Fill(GVER->ge_x[1]-rYver);
00365 LOG_INFO<< Form(
"Z Geant-found=%.2f, dx=%.2f, dy=%.2f\n",GVER->ge_x[2]-rZver,GVER->ge_x[0]-rXver,GVER->ge_x[1]-rYver)<<endm;
00366 }
00367
00368 }
00369
00370
00371
00372
return kStOk;
00373 }
00374
00375
00376
00377
00378
00379
void StVertexMaker::ppLMVuse(
int *parI,
float *parF) {
00380
const char *nameI[]={
"CtbThres/ch",
"MinTrkPonits",
"beamEequivNtr",
"MinMatchTr",
"i4",
"i5",
"i6",
"i7",
"i8",
"i9"};
00381
const char *nameF[]={
"CtbThres/MeV",
"MaxTrkDcaRxy",
"MinTrkPt/GeV",
"CtbEtaErr",
"CtbPhiErr/deg",
"MaxTrkDcaZ",
"f6",
"f7",
"f8",
"f9"};
00382 LOG_INFO<<
"\nppLMV use new set of params\n INT: "<<endm;
00383
int i;
00384
for( i=0;i<10;i++) {
00385 ppLMVparI[i]=parI[i];
00386 LOG_INFO<<Form(
"%s=%d ", nameI[i],ppLMVparI[i])<<endm;
00387 }
00388 LOG_INFO<<Form(
"\n FLOAT: ")<<endm;
00389
for( i=0;i<10;i++) {
00390 ppLMVparF[i]=parF[i];
00391 LOG_INFO<<Form(
"%s=%f ", nameF[i],ppLMVparF[i])<<endm;
00392 }
00393
00394 zCutppLMV=ppLMVparF[5];
00395 }
00396
00397