00001 #include <stdio.h>
00002 #include <math.h>
00003 #include <assert.h>
00004 #include <TObjArray.h>
00005 #include <TH1.h>
00006 #include <TH2.h>
00007 #include <TLine.h>
00008 #include <TList.h>
00009
00010 #include "UtilBeamLine3D.h"
00011
00012
00013
00014 UtilBeamLine3D::UtilBeamLine3D() {
00015 track.clear();
00016 fcnCount=0;
00017
00018 cut_maxRxy=1.5;
00019 cut_maxZ=100;
00020 cut_minChi2=0.4;
00021 cut_maxChi2=2.;
00022 cut_minP=1.2;
00023
00024 cut_Dmax=1.0;
00025 par_filter=0;
00026 printf("constr of UtilBeamLine3D \n");
00027 }
00028
00029
00030
00031 void
00032 UtilBeamLine3D:: initHisto( TObjArray * HList){
00033 TList *L=0; TLine *ln=0; float yMax=1e6; TH1* h=0;
00034
00035 memset(hA,0,sizeof(hA));
00036 printf("helper:initHist\n");
00037
00038 hA[0]=new TH1F("trStat","statistics for tracks",20,0.5,20.5);
00039
00040 hA[1]=h=new TH1F("trCh2","input track chi2; chi2/dof",100,0,10);
00041 ln=new TLine(cut_minChi2,0,cut_minChi2,yMax);
00042 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00043 L= h->GetListOfFunctions(); L->Add(ln);
00044 ln=new TLine(cut_maxChi2,0,cut_maxChi2,yMax);
00045 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00046 L= h->GetListOfFunctions(); L->Add(ln);
00047
00048 hA[2]=h=new TH1F("trZ","input track Z @DCA; Z(cm)",50,-200,200);
00049 ln=new TLine(cut_maxZ,0,cut_maxZ,yMax);
00050 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00051 L= h->GetListOfFunctions(); L->Add(ln);
00052 ln=new TLine(-cut_maxZ,0,-cut_maxZ,yMax);
00053 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00054 L= h->GetListOfFunctions(); L->Add(ln);
00055
00056 hA[3]=h=new TH1F("trX","input track X @DCA; X(cm)",100,-4,4);
00057 ln=new TLine(cut_maxRxy,0,cut_maxRxy,yMax);
00058 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00059 L= h->GetListOfFunctions(); L->Add(ln);
00060 ln=new TLine(-cut_maxRxy,0,-cut_maxRxy,yMax);
00061 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00062 L= h->GetListOfFunctions(); L->Add(ln);
00063
00064 hA[4]=h=new TH1F("trY","input track Y @DCA; Y(cm)",100,-4,4);
00065 ln=new TLine(cut_maxRxy,0,cut_maxRxy,yMax);
00066 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00067 L= h->GetListOfFunctions(); L->Add(ln);
00068 ln=new TLine(-cut_maxRxy,0,-cut_maxRxy,yMax);
00069 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00070 L= h->GetListOfFunctions(); L->Add(ln);
00071
00072 hA[5]=h=new TH1F("trP","input track momentum P @DCA; P (GeV/c)",100,0,10);
00073 ln=new TLine(cut_minP,0,cut_minP,yMax);
00074 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00075 L= h->GetListOfFunctions(); L->Add(ln);
00076
00077 hA[6]=new TH1F("trPt","input track momentum PT @DCA; PT (GeV/c)",100,0,10);
00078
00079
00080 hA[13]=h= new TH2D("fcnChiXY","ln(3D likelihood), STAR X-Y plane; X-axis (cm); Y-axis(cm)",60,-.8,.8,60,-.8,.8);
00081 ln=new TLine(-10,0,10,0); ln->SetLineColor(kMagenta);
00082 L= h->GetListOfFunctions(); L->Add(ln);
00083 ln=new TLine(0,-10,0,10); ln->SetLineColor(kMagenta);
00084 L= h->GetListOfFunctions(); L->Add(ln);
00085
00086 hA[14]=h= new TH2D("fcnChiXnX","ln(3D likelihood), STAR X-n_{X} plane; X-axis (cm); slope X ",60,0,1,60,-2e-3,2e-3);
00087 ln=new TLine(0,-10,0,10); ln->SetLineColor(kMagenta);
00088 L= h->GetListOfFunctions(); L->Add(ln);
00089
00090 hA[15]=h= new TH2D("fcnChiYnY","ln(3D likelihood), STAR Y-n_{Y} plane; Y-axis (cm); slope Y ",60,0,1,60,-2e-3,2e-3);
00091 ln=new TLine(0,-10,0,10); ln->SetLineColor(kMagenta);
00092 L= h->GetListOfFunctions(); L->Add(ln);
00093
00094
00095 hA[19]=h=new TH1F("bmSol","Solution of 3D fit, beam line params; value",1,1,1);
00096 h->SetMarkerStyle(20);
00097
00098
00099 hA[20]=new TH1F("fcnDet","FCN: determinant from DCA solution",200,0,1.01);
00100 hA[21]=h=new TH1F("fcnDca","FCN: 3D dca length ...; DCA (cm)",100,0,5.);
00101 ln=new TLine(cut_Dmax,0,cut_Dmax,yMax);
00102 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00103 L= h->GetListOfFunctions(); L->Add(ln);
00104
00105 hA[22]=h=new TH2F("fcnDcaZ","FCN: 3D dca length; Z (cm);DCA (cm)",50,-200,200.,50,0,5.);
00106 ln=new TLine(-200,cut_Dmax,200,cut_Dmax);
00107 ln->SetLineColor(kRed); ln->SetLineStyle(2);
00108 L= h->GetListOfFunctions(); L->Add(ln);
00109 hA[23]=h=new TH1F("fcnNtr","FCN: # of tracks with 3D.DCA<Dmax ; Z (cm)",50,-200,200.);
00110 h->SetLineColor(kBlue); h->SetFillColor(kBlue);
00111
00112 for(int i=0;i<mxH; i++) if(hA[i]) HList->Add(hA[i]);
00113 printf("track QA params: maxRxy<%.1f cm, maxZ<%.1f cm, chi2/dof=[%.1f, %.1f], Dmax=%.2f cm track filter=%d\n", cut_maxRxy, cut_maxZ, cut_minChi2,cut_maxChi2,cut_Dmax,par_filter);
00114
00115 }
00116
00117
00118
00119
00120 void
00121 UtilBeamLine3D::qaTracks(){
00122 printf("qaTRacks start=%d\n",(int)track.size());
00123 int nOK=0;
00124 vector<TrackStump>::iterator it;
00125 for (it=track.begin() ; it < track.end(); it++ ) {
00126 TrackStump *t= &(*it);
00127 hA[0]->Fill(1);
00128
00129 hA[1]->Fill(t->chi2);
00130 if( t->chi2<cut_minChi2 || t->chi2>cut_maxChi2) continue;
00131 hA[0]->Fill(2);
00132
00133 hA[2]->Fill(t->r.z());
00134 if(fabs(t->r.z()) >cut_maxZ) continue;
00135 hA[0]->Fill(3);
00136
00137 hA[3]->Fill(t->r.x());
00138 if(fabs(t->r.x()) >cut_maxRxy) continue;
00139 hA[0]->Fill(4);
00140
00141 hA[4]->Fill(t->r.y());
00142 if(fabs(t->r.y()) >cut_maxRxy) continue;
00143 hA[0]->Fill(5);
00144
00145 hA[5]->Fill(t->P);
00146 if(t->P<cut_minP) continue;
00147 hA[0]->Fill(6);
00148
00149 if(par_filter==1) {
00150 if(t->r.z()< 0 || t->p.z() <0) continue;
00151 }
00152 hA[0]->Fill(7);
00153
00154
00155
00156 t->bad=0;
00157 nOK++;
00158 hA[6]->Fill(t->Pt);
00159 }
00160 printf("qaTRacks end=%d\n",nOK);
00161 }
00162
00163
00164
00165
00166 void
00167 UtilBeamLine3D::print(int k) {
00168 printf("UtilBeamLine3D::print(%d) size=%d\n",k,(int)track.size());
00169 for(int i=0;i<(int)track.size();i++) {
00170 track[i].print();
00171 if(i>=k) break;
00172 }
00173 }
00174
00175
00176
00177 void
00178 UtilBeamLine3D::scanChi2(double *par, int mode){
00179 assert(mode==0 || mode==1);
00180
00181 printf("scan chi2, mode=%d ....\n",mode);
00182
00183 int npar,iflag=0;
00184 double *grad=0;
00185 double fcnval;
00186 double wrkPar[mxPar];
00187
00188
00189
00190
00191 TH2F *h2=0;
00192 if(mode==0) h2=(TH2F*)hA[13];
00193 if(mode==1) h2=(TH2F*)hA[14];
00194 if(mode==2) h2=(TH2F*)hA[15];
00195 TAxis *xax=h2->GetXaxis();
00196 TAxis *yax=h2->GetYaxis();
00197
00198 if(mode==0) {
00199 if(fabs(par[0])>0.5 ||fabs(par[1])>0.5 ){
00200 xax->Set(xax->GetNbins(),par[0]-0.8,par[0]+0.8);
00201 yax->Set(yax->GetNbins(),par[1]-0.8,par[1]+0.8);
00202 }
00203 }
00204 if(mode==1) {
00205 xax->Set(xax->GetNbins(),par[0]-0.8,par[0]+0.8);
00206 yax->Set(yax->GetNbins(),par[2]-4e-2,par[2]+4e-2);
00207 }
00208 for(int bx=1;bx<=xax->GetNbins();bx++){
00209 double x=xax->GetBinCenter(bx);
00210 for(int by=1;by<=yax->GetNbins();by++){
00211 double y=yax->GetBinCenter(by);
00212 if(mode==0) {
00213 wrkPar[0]=x; wrkPar[1]=y;
00214 wrkPar[2]=par[2]; wrkPar[3]=par[3];
00215 }
00216 if(mode==1) {
00217 wrkPar[0]=x; wrkPar[1]=par[1];
00218 wrkPar[2]=y; wrkPar[3]=par[3];
00219 }
00220
00221 beamLineLike3D(npar,grad,fcnval, wrkPar,iflag);
00222
00223 h2->Fill(x,y,fcnval);
00224 }
00225 }
00226
00227 }
00228
00229
00230 void
00231 UtilBeamLine3D::evalSolution(double *par){
00232
00233 int npar,iflag=0;
00234 double *grad=0;
00235 double fcnval;
00236
00237 fcnMon1=1;
00238 beamLineLike3D(npar,grad,fcnval, par,iflag);
00239 }
00240
00241
00242
00243
00244 void
00245 UtilBeamLine3D::readTracks(const TString fnameT){
00246 const char *fname=fnameT.Data();
00247 printf("Read fname=%s=\n",fname);
00248 FILE *fd=fopen(fname,"r"); assert(fd);
00249 char text[1000];
00250 TrackStump t;
00251 float x,y,z,px,py,pz,ery,eryz,erz;
00252 track.clear();
00253 while(1) {
00254 int ret= fscanf(fd,"%s %f %f %f %f %f %f %f %f %f %d %f %f %d,",text,&x,&y,&z,&px,&py,&pz,&ery,&eryz,&erz,&t.nFitP,&t.chi2,&t.z0,&t.eveId);
00255
00256 if(ret!=14) break;
00257
00258
00259 t.r.SetXYZ(x,y,z);
00260 t.p.SetXYZ(px,py,pz);
00261 t.P=t.p.Mag();
00262 t.Pt=t.p.Pt();
00263 t.p=t.p.Unit();
00264 t.ery2=ery*ery;
00265 t.eryz=eryz;
00266 t.erz2=erz*erz;
00267 t.bad=1;
00268 track.push_back(t);
00269
00270 }
00271 printf("found %d tracks\n",(int)track.size());
00272 fclose(fd);
00273 }