StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleReader.C
1 // $Id: ExampleReader.C,v 1.2 2008/12/29 16:12:48 kocolosk Exp $
2 
3 /*****************************************************************************
4  * @author Adam Kocoloski
5  *
6  * Quick example showing how to read StChargedPionEvent trees.
7  *****************************************************************************/
8 
9 void ExampleReader(const char *path = "/star/institutions/mit/common/run6-trans/chargedPions/chargedPions_7097009.tree.root") {
10  gROOT->Macro("StRoot/StSpinPool/StChargedPionAnalysisMaker/macros/LoadLibs.C");
11 
12  TFile *f = TFile::Open(path);
13  TTree *tree = (TTree*)f->Get("tree");
15  tree->SetBranchAddress("event", &event);
16 
17  for(int i=0; i<3; i++) {
18  tree->GetEntry(i);
19 
20  cout << "run: " << event->runId() << " event: " << event->eventId();
21 
22  if( event->vertex(0) )
23  cout << " vz: " << event->vertex(0)->Z() << endl;
24 
25  for(int j=0; j<event->nJets(); j++) {
26  cout << " jet #" << j+1 << " ";
27  cout << "pt: " << event->jet(j)->Pt() << " "
28  << "eta: " << event->jet(j)->Eta() << " "
29  << "phi: " << event->jet(j)->Phi() << endl;
30 
31  int nparticles = (event->jet(j)->particles()).size();
32  for(int k=0; k<nparticles; k++) {
33  StChargedPionJetParticle& p(event->jet(j)->particles()[k]);
34  cout << " particle #" << k+1 << " "
35  << " charge " << p.charge() << " "
36  << " pt " << p.Pt() << " "
37  << " eta " << p.Eta() << endl;
38  }
39  }
40  }
41 }
42 
43 /*****************************************************************************
44  * $Log: ExampleReader.C,v $
45  * Revision 1.2 2008/12/29 16:12:48 kocolosk
46  * added $Id$/$Log$ as needed
47  *
48  *****************************************************************************/
49