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 void Example_read_dst_makehist(
00047 Int_t nevents=3,
00048 const char *MainFile=
00049 "/afs/rhic.bnl.gov/star/data/samples/gstar.dst.root")
00050 {
00051
00052 gSystem->Load("St_base");
00053 gSystem->Load("StChain");
00054
00055 gSystem->Load("libglobal_Tables");
00056 gSystem->Load("libgen_Tables");
00057 gSystem->Load("libsim_Tables");
00058
00059 gSystem->Load("StIOMaker");
00060 gSystem->Load("StarClassLibrary");
00061
00062
00063
00064 chain = new StChain("bfc");
00065 chain->SetDebug();
00066
00067
00068 StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,"bfcTree");
00069 IOMk->SetDebug();
00070 IOMk->SetIOMode("r");
00071 IOMk->SetBranch("*",0,"0");
00072
00073
00074 IOMk->SetBranch("dstBranch",0,"r");
00075
00076
00077
00078 chain->Init();
00079
00080
00081 TFile *hist_outfile = 0;
00082 const Char_t *root_file = "Example_read_dst_makehist.root";
00083 hist_outfile = new TFile(root_file,"RECREATE");
00084
00085
00086 TH1F *h1 = new TH1F("h1","z position of primary vertex",100,-100.,100.);
00087 h1->SetXTitle("vertex z position ");
00088 h1->SetYTitle("num events");
00089 TH1F *h2 = new TH1F("h2","z position of all vtx in event",100,-100.,100.);
00090 h2->SetXTitle("vertex z position ");
00091 h2->SetYTitle("num events");
00092
00093 for (int iev=0;iev<nevents; iev++)
00094 {
00095 chain->Clear();
00096 int iret = chain->Make();
00097 if (iret) break;
00098
00099 cout << " !!!!! Now read event # " << iev << endl;
00100
00101 TDataSet *ds=chain->GetDataSet("dst/vertex");
00102 TDataSetIter dsiter(ds);
00103 St_dst_vertex *vert = (St_dst_vertex *) dsiter.Find("vertex");
00104
00105 cout << " vertex table pointer = " << vert << endl;
00106
00107
00108
00109
00110 if (!vert) continue;
00111
00112
00113
00114 cout << " table header info: name = " << vert->GetName() << endl;
00115 cout << " table header info: type = " << vert->GetType() << endl;
00116 cout << " table header info: #rows used = " << vert->GetNRows() << endl;
00117 cout << " table header info: #rows allocated = " << vert->GetTableSize() << endl;
00118 cout << " table header info: row size (bytes) = " << vert->GetRowSize() << endl;
00119 cout << " table header info: #columns = " << vert->GetNumberOfColumns() << endl;
00120
00121
00122 vert->ls();
00123
00124
00125
00126 dst_vertex_st *sth = vert->GetTable();
00127 cout << " prim vtx z : " << sth->z << endl;
00128
00129
00130 h1->Fill(sth->z);
00131
00132
00133 Int_t ij = 0;
00134 for (ij=0; ij< vert->GetNRows(); ij++)
00135 {
00136 h2->Fill(sth[ij]->z);
00137 }
00138
00139 }
00140
00141 cout << " ==> finished loop" << endl;
00142
00143 TCanvas *c1 = new TCanvas("c1"," from table dst/vertex",200,10,600,880);
00144
00145
00146 c1->SetGrid();
00147
00148 c1->Divide(1,2);
00149
00150
00151 TPostScript ps("Example_read_dst_makehist.ps",111);
00152
00153
00154
00155 h1->Draw();
00156 c1->Update();
00157 h2->Draw();
00158 c1->Update();
00159
00160 hist_outfile->Write();
00161 hist_outfile->ls();
00162
00163 ps.Close();
00164
00165 }
00166
00167
00168
00169