StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
anaEEexample.C
1 // read TTree
2 
3 anaEEexample(int neve=300, TString Tname0="/star/u/eemcdb/dataFeb11/run00006.eeTree", int flag=0, float Emax=40.){
4  TString Tname0="../sim2003/mc_eve2";
5  gSystem->Load("StRoot/StEEmcUtil/EEevent/libEEevent.so");
6  gSystem->Load("StRoot/StEEmcUtil/anaEE/libanaEE.so");
7 
8  // gStyle->SetPalette(1,0);
9  gStyle->SetOptStat(111111);
10 
11  TString Tname;
12  Tname=Tname0;
13 
14  TFile *of=new TFile(Tname+"hist.root","recreate"); // output histogram file
15  anaEEexample ana(of);
16 
17 
18  printf("read upto %d events from file=%s.root\n",neve,Tname.Data());
19  TFile *f = new TFile(Tname+".root");
20  assert(f->IsOpen());
21  TTree *t4 = (TTree*)f->Get("EEtree");
22  assert(t4);
23  // create a pointer to an event object. This will be used
24  // to read the branch values.
25  EEeventDst *event = new EEeventDst();
26 
27  //if (gROOT->IsBatch()) return; new TBrowser(); t4->StartViewer(); return;
28  TBranch *br = t4->GetBranch("EEdst");
29  br->SetAddress(&event);
30  Int_t nevent = (Int_t)t4->GetEntries();
31 
32  // ............... LOOP over events
33  for (Int_t ie=0;ie<nevent;ie++) {
34  if(ie>=neve) break;
35  printf("\niEve=%d ---------- \n",ie);
36 
37  br->GetEntry(ie);
38  //event->print();
39  ana.process(event);
40  }
41 
42  printf("\n\nTotal events in B TTree=%d\n",nevent);
43 
44  of->ls();
45  of->Write();
46  TH1F* h0=(TH1F* )of->Get("de");
47  h0->Draw();
48 
49 }
50 
51 
52 
53 #if 0
54 
55  // allocate memory for needed branches
56  TClonesArray *secA=new TClonesArray("EEsectorDst",1000);
57  TBranch *BRsec = t4->GetBranch("Sec"); // set the branch address
58  BRsec->SetAddress(&secA);
59 
60  int eveID=0;
61  TBranch *BRid = t4->GetBranch("ID");
62  BRid->SetAddress(&eveID);
63 
64  Int_t nevent = (Int_t)t4->GetEntries();
65  printf("Total events in TTree=%d\n",nevent);
66 
67 
68  // ........... LOOP OVER EVENTS ............
69 
70  for (Int_t ie=0;ie<nevent;ie++) {
71  if(ie>=neve) break;
72  int i;
73 
74  //read this branch only
75  BRid->GetEntry(ie);
76  BRsec->GetEntry(ie);
77 
78  if(ie%1==0) printf("\n\iEve=%d nSec=%d with data \n",ie,secA->GetEntries());
79 
80  // if(ie%1==0) printf("\n\iEve=%d eveID=%d, eveType=%d, nSec=%d with data :\n",ie,eveID,eveType,secA->GetEntries());
81  if(ie%1==0) printf("\n\iEve=%d eveID=%d, nSec=%d with data :\n",ie,eveID,secA->GetEntries());
82 
83 
84  int is;
85  for(is=0;is<secA->GetEntries();is++) {
86  EEsectorDst *sec=(EEsectorDst*)secA->At(is);
87  if(ie<1) sec->print();
88 
89  TClonesArray *hitA;
90  int ih;
91 
92  TClonesArray *hitAA[]={sec->getPre1Hits(),sec->getPre2Hits(),sec->getTwHits(),sec->getPostHits(),sec->getSmdUHits(),sec->getSmdVHits()};
93  int iz;
94  for(iz=0;iz<4;iz++) { // over tower/pre/post
95  hitA=hitAA[iz];
96  if(ie<1) printf(" sectorID=%d iz=%d nHit=%d :\n",sec->getID(),iz,hitA->GetEntries());
97  }// end of loop over pre1/2/Tw/Post
98 
99 
100  for(iz=4;iz<6;iz++) { // over SMD U/V
101  hitA=hitAA[iz];
102  if(ie<1) printf(" sectorID=%d iz=%d nHit=%d :\n",sec->getID(),iz,hitA->GetEntries());
103  for(ih=0;ih<hitA->GetEntries();ih++) {
104  EEsmdHitDst *hit2=(EEsmdHitDst*)hitA->At(ih);
105  int strip;
106  float ener;
107  hit2->get(strip,ener);
108  if(ie<1) printf(" ih=%d strip=%d etaBin=%d ener=%f\n",ih, sec->getID(), strip,ener);
109  hit->print();
110  }
111  }// end of loop over pre1/2/Tw/Post
112 
113 
114  }// end of loop over sector
115 
116  }
117 #endif
118 
119 
120 
121 
122