00001 void Example_tags(TString topDir = "/star/rcf/GC/daq/tags")
00002 {
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00017 gSystem->Load("libTable");
00018 gSystem->Load("St_base");
00019
00020 gBenchmark = new TBenchmark();
00021 gBenchmark->Start("total");
00022
00023
00024 gROOT->ProcessLine(".O4");
00025
00026
00027 topDir +='/';
00028 St_FileSet dirs(topDir);
00029 St_DataSetIter next(&dirs,0);
00030 St_DataSet *set = 0;
00031 TChain chain("Tag");
00032 while ( (set = next()) ) {
00033 if (strcmp(set->GetTitle(),"file") ||
00034 !(strstr(set->GetName(),".tags.root"))) continue;
00035 chain.Add(gSystem->ConcatFileName(topDir,set->Path()));
00036 }
00037 UInt_t nEvents = chain->GetEntries();
00038 cout<<"chained "<<nEvents<<" events "<<endl;
00039
00040 TObjArray *files = chain.GetListOfFiles();
00041 UInt_t nFiles = files->GetEntriesFast();
00042 cout << "chained " << nFiles << " files from " << topDir << endl;
00043
00044 TObjArray *leaves = chain.GetListOfLeaves();
00045 Int_t nleaves = leaves->GetEntriesFast();
00046
00047 TString tableName = " ";
00048 TObjArray *tagTable = new TObjArray;
00049
00050 Int_t tableCount = 0;
00051 Int_t *tableIndex = new Int_t[nleaves];
00052 Int_t tagCount = 0;
00053
00054
00055 for (Int_t l=0;l<nleaves;l++) {
00056 TLeaf *leaf = (TLeaf*)leaves->UncheckedAt(l);
00057 tagCount+=leaf->GetNdata();
00058 TBranch *branch = leaf->GetBranch();
00059
00060 if ( strstr(branch->GetName(), tableName.Data()) == 0 ) {
00061 tableName = branch->GetName();
00062
00063 tableName.Resize(tableName->Last('.'));
00064 tagTable->AddLast(new TObjString(tableName.Data()));
00065 tableCount++;
00066 }
00067 tableIndex[l]=tableCount-1;
00068 }
00069 cout << " tot num tables, tags = " << tableCount << " "
00070 << tagCount << endl << endl;
00071
00072
00073 for (l=0;l<nleaves;l++) {
00074 leaf = (TLeaf*)leaves->UncheckedAt(l);
00075 branch = leaf->GetBranch();
00076 branch->GetEntry();
00077
00078 TString Title = leaf->GetTitle();
00079 Int_t dim = leaf->GetNdata();
00080 if (dim==1) {
00081 Title.ReplaceAll('['," '");
00082 Title.ReplaceAll(']',"'");
00083 }
00084 cout << "\n Table: ";
00085 cout.width(10);
00086 cout << ((TObjString*)tagTable->UncheckedAt(tableIndex[l]))->GetString()
00087 <<" -- has tag: " << Title << endl;
00088 for (Int_t i=0;i<dim;i++) {
00089 cout <<" "<< leaf->GetName();
00090 if (dim>1) cout << '['<<i<<']';
00091 cout << " = " << leaf->GetValue(i) << endl;
00092 }
00093 }
00094
00095
00096 c1 = new TCanvas("c1","Beam-Gas Rejection",600,1000);
00097 gStyle->SetMarkerStyle(8);
00098 chain->Draw("n_trk_tpc[0]:n_trk_tpc[1]");
00099
00100
00101 Int_t ncoll=0;
00102 char aevent[10];
00103 TText t(0,0,"a");
00104 t.SetTextFont(52);
00105 t.SetTextSize(0.02);
00106 Float_t cut = 0.35;
00107 cout <<"\n Events with ntrk>400 and |asim|<"<<cut<<endl;
00108
00109 gBenchmark->Start("loop");
00110 for (Int_t i=0;i<nFiles;i++) {
00111 chain.LoadTree(*(chain.GetTreeOffset()+i));
00112 TTree *T = chain.GetTree();
00113
00114 TLeaf *ntrk = T->GetLeaf("n_trk_tpc");
00115 TLeaf *run = T->GetLeaf("mRunNumber");
00116 TLeaf *event = T->GetLeaf("mEventNumber");
00117 for (Int_t j=0; j<T->GetEntries(); j++){
00118 ntrk->GetBranch()->GetEntry(j);
00119 event->GetBranch()->GetEntry(j);
00120 run->GetBranch()->GetEntry(j);
00121 Int_t Nm=ntrk->GetValue(0);
00122 Int_t Np=ntrk->GetValue(1);
00123 Int_t Ntrk = Np+Nm;
00124
00125 Float_t asim = Np-Nm;
00126 if (Ntrk>0) asim /= Ntrk;
00127 if (-cut < asim&&asim < cut && Ntrk>400) {
00128 cout<<" Run "<<(UInt_t)run->GetValue()
00129 <<", Event "<<event->GetValue() <<endl;
00130 ncoll++;
00131 sprintf(aevent,"%d",event->GetValue());
00132 t.DrawText(Np+10,Nm+10,aevent);
00133 }
00134 }
00135 }
00136 gBenchmark->Stop("loop");
00137 t.SetTextSize(0.05);
00138 t.DrawText(50,2550,"ntrk>400 and |(Np-Nm)/(Np+Nm)| < 0.35 ");
00139 t.DrawText(500,-300,"Ntrk with tanl<0 ");
00140 cout << " Selected " << ncoll << " collision candidates out of "
00141 << nEvents << " events" << endl;
00142
00143 gBenchmark->Print("loop");
00144 gBenchmark->Stop("total");
00145 gBenchmark->Print("total");
00146 }