St_dst_Maker/ppLMV4.cxx

00001 // $Id: ppLMV4.cxx,v 1.14 2007/05/30 02:38:57 balewski Exp $ 00002 // $Log: ppLMV4.cxx,v $ 00003 // Revision 1.14 2007/05/30 02:38:57 balewski 00004 // replace printf -->LOG_XXX 00005 // 00006 // Revision 1.13 2007/04/28 17:55:48 perev 00007 // Redundant StChain.h removed 00008 // 00009 // Revision 1.12 2004/12/16 00:29:56 jeromel 00010 // Modifications (shall we say hack ?) to implement the ppLMV-5 cuts to 00011 // ppLMV4. 00012 // 00013 // Revision 1.11 2003/09/02 17:59:26 perev 00014 // gcc 3.2 updates + WarnOff 00015 // 00016 // Revision 1.10 2002/03/25 19:35:07 balewski 00017 // correct ppLMV for 0filed, still not vry good 00018 // 00019 // Revision 1.9 2002/02/25 21:12:45 balewski 00020 // correct wrong usage of hlx.pathLength(x,y) 00021 // 00022 // Revision 1.8 2002/02/22 04:36:11 genevb 00023 // Set vertex id to vertex table entry row 00024 // 00025 // Revision 1.7 2002/02/18 19:48:20 genevb 00026 // Separation of primary vertex and track finding, other minor changes 00027 // 00028 // *** empty log message *** 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" // only for histo 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 //static const char rcsid[] = "$Id: ppLMV4.cxx,v 1.14 2007/05/30 02:38:57 balewski Exp $"; 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 //int bXing=maTrk.getTrigBXing(); 00080 //int bXing=maTrk.getPileupBXing(); 00081 int bXing=trigBXing;// temp 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 // Get BField from gufld(,) 00092 // cout<<"Trying to Get the BField the old way..."<<endl; 00093 float x[3] = {0,0,0}; 00094 float b[3]; 00095 gufld(x,b); 00096 double bfield = 0.1*b[2]; //This is now Tesla. 00097 if(fabs(bfield)<0.0001) bfield=0.00222; // to make helix heappy 00098 00099 00100 if( beam4ppLMV.isOn) { // add beam line to ppLMV to constrain vertex 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){ // beam line _MUST_ be tilted 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; // approximation: nx,ny<<0 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; // marker for the beam line 00117 trk1.helix=StPhysicalHelixD (MomFstPt, origin, bfield*tesla, 1.); 00118 00119 float sigMin=100000; // pick large weight for this track 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); //<== assigne weight 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 // Parameters 00135 double DVtxMax = 4.0; 00136 00137 // Determine if SVT is in or not, depending on geometry and date in db 00138 long Is_SVT = 0; 00139 if( mdate > 20000700 )Is_SVT=1; 00140 00141 00142 // ---------- D O F I N D V E R T E X 00143 00144 // printf("%s - search for vertex using %d matched tracks: start ...\n",GetName(),(*tracks).size()); 00145 00146 double xo=0.0,yo=0.0; 00147 if( beam4ppLMV.equivNtr>0) {// use the beam line as a starting point 00148 xo=beam4ppLMV.x0; 00149 yo=beam4ppLMV.y0; 00150 } 00151 00152 //Do the actual vertex fitting, continue until good 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; // Matrix Elements 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; // C = A^-1 00157 int done = 0; 00158 double chi2=0; 00159 StThreeVectorD XVertex(999.,888.,777.); 00160 while( done != 1 ){ 00161 00162 // Check that there at least are 2 tracks 00163 if( (*tracks).size() <= 1 ){ 00164 cout<<"ppLMV: Fewer than 2 track remains. No vertex found."<<endl; 00165 return kStWarn; 00166 } 00167 00168 // Begin by doing a fit 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; // Matrix Elements 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; // C = A^-1 00173 double b1=0.0,b2=0.0,b3=0.0; 00174 // Compute matrix A and vector b 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 // printf("itr=%d DCA x=%f y=%f z=%f sig=%f\n",itr,xp,yp,zp,(*tracks)[itr].sigma); 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 // Invert A 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 // cout<<"Determinant= "<<detA<<endl; 00202 // cout<<"A11,A12,A13: "<<A11<<" "<<A12<<" "<<A13<<endl; 00203 // cout<<"A21,A22,A23: "<<A21<<" "<<A22<<" "<<A23<<endl; 00204 // cout<<"A31,A32,A33: "<<A31<<" "<<A32<<" "<<A33<<endl; 00205 // cout<<"b1,b2,b3 "<<b1<<" "<<b2<<" "<<b3<<endl; 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 // Find Vertex Position 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 // cout<<"Vertex Position : "<<XVertex.x()<<" "<<XVertex.y()<<" "<<XVertex.z()<<endl; 00216 // cout<<"Error in Position : "<<::sqrt(C11)<<" "<<::sqrt(C22)<<" "<<::sqrt(C33)<<endl; 00217 00218 00219 // Check if the fit is any good 00220 // Loop over tracks again to get Chi2 and check each track's deviation 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;}// beamLine track 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; // do not use sig during track rejection; 00244 // printf(" DCA x=%f y=%f z=%f d=%f drel=%f dmax=%f\n",XHel.x(),XHel.y(),XHel.z(),d,drel,dmax); 00245 if( drel > dmax ){ 00246 // Save the track that deviates the most from vertex 00247 dmax = drel; 00248 i1keep = itehlx; 00249 } 00250 00251 itehlx++; 00252 } 00253 00254 if( dmax > DVtxMax ){ 00255 // cout<<"Removing a track! dmax= "<<dmax<<endl; 00256 (*tracks).erase(i1keep); 00257 done=0; 00258 } 00259 else{ 00260 done=1; 00261 } 00262 } // End While Loop 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; //By definition 00276 00277 // printf(" Fill the dst_vertex table\n"); 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; //TPC track by definition 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; // Need to find the prob func in Root 00301 vertex->AddAt(&primvtx,nrows); 00302 00303 // printf(" Mark the vertex tracks in the global_trk table\n"); 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 // This track was included in the Vertex 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 // mark also other global tracks close enough to the vertex 00323 00324 for(uint j=0;j<maTrk.primCan.size(); j++) { 00325 // printf("glob j=%d x,y,z %f %f %f trID=%d verID=%d\n",j, maTrk.primCan[j].x0,maTrk.primCan[j].y0,maTrk.primCan[j].z0,maTrk.primCan[j].glb_track_pointer->id,maTrk.primCan[j].glb_track_pointer->id_start_vertex); 00326 if(maTrk.primCan[j].glb_track_pointer->id_start_vertex>=10) continue; // already marked 00327 double dz=maTrk.primCan[j].z0 - XVertex.z(); 00328 if(fabs(dz)>DVtxMax) continue; // too fare in Z 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; // too fare in X*Y*Z 00334 maTrk.primCan[j].glb_track_pointer->id_start_vertex+=10*IVertex ; 00335 } 00336 00337 {// fill some histos 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 // -------------- A C C E S S G E A N T V E R T E X (for histo) 00359 g2t_vertex_st *GVER=(g2t_vertex_st *)maTrk.GVER[bXing]; 00360 // printf("GVER add=%d\n",GVER); 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 } // end of histos 00369 00370 00371 // printf("end of ppLMV\n"); 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

Generated on Sun Mar 15 04:51:02 2009 for StRoot by doxygen 1.3.7