StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
runGammaTreeReader.C
1 class StGammaEvent;
3 class StGammaCandidate;
4 
5 #define __TEST__
6 
7 TFile *file = 0;
8 TTree *tree = 0;
9 TChain *chain = 0;
10 
11 StGammaEvent *event = 0;
12 StGammaTreeReader *reader = 0;
13 
14 // ------------------------------------------------------------------------------
15 //
16 // 1. cvs co offline/StGammaMaker
17 // 2. mkdir StRoot
18 // 3. cp -R offline/StGammaMaker StRoot/
19 // 4. cons
20 // 5. ln -s StRoot/StGammaMaker/macros/runGammaTreeReader.C .
21 // 6. root4star -q -b runGammaTreeReader.C
22 // 7. meh
23 //
24 // ------------------------------------------------------------------------------
25 
26 void runGammaTreeReader( int nevents=-1,
27  const Char_t *fname = "/auto/pdsfdv34/starspin/jwebb/2008/02-29-2008-gammas-with-preshower/7864/7136073/",
28  const Char_t *oname = "testgammas.root" )
29 {
30 
31  gROOT->LoadMacro("StRoot/StGammaMaker/macros/loadGammaLibs.C");
32  loadGammaLibs();
33 
34 
35  reader = new StGammaTreeReader("gammas","GammaEvent"); // reads in the event branch
36  reader -> Init(); // should be (but isn't) part of a chain
37 
38  // Files exist at PDSF
39  chainFiles( "/auto/pdsfdv34/starspin/jwebb/2008/02-29-2008-gammas-with-preshower/7864/7136073/");
40  chainFiles( "/auto/pdsfdv34/starspin/jwebb/2008/02-29-2008-gammas-with-preshower/7864/7136080/");
41 
42  /* few example events from above chains
43 
44  [0] RUN: 7136073 EVENT: 2721 KEY: 71360730000002721 INDEX: 0
45  [1] RUN: 7136073 EVENT: 3548 KEY: 71360730000003548 INDEX: 1
46  [2] RUN: 7136073 EVENT: 3918 KEY: 71360730000003918 INDEX: 2
47  [3] RUN: 7136073 EVENT: 6433 KEY: 71360730000006433 INDEX: 3
48  [4] RUN: 7136073 EVENT: 7587 KEY: 71360730000007587 INDEX: 4
49  [5] RUN: 7136073 EVENT: 12476 KEY: 71360730000012476 INDEX: 5
50  [6] RUN: 7136073 EVENT: 14475 KEY: 71360730000014475 INDEX: 6
51  [7] RUN: 7136073 EVENT: 16295 KEY: 71360730000016295 INDEX: 7
52  [8] RUN: 7136073 EVENT: 25487 KEY: 71360730000025487 INDEX: 8
53  [9] RUN: 7136073 EVENT: 25769 KEY: 71360730000025769 INDEX: 9
54 
55  [0] RUN: 7136080 EVENT: 81123 KEY: 71360800000081123 INDEX: 0
56  [1] RUN: 7136080 EVENT: 81130 KEY: 71360800000081130 INDEX: 1
57  [2] RUN: 7136080 EVENT: 81133 KEY: 71360800000081133 INDEX: 2
58  [3] RUN: 7136080 EVENT: 81141 KEY: 71360800000081141 INDEX: 3
59  [4] RUN: 7136080 EVENT: 81147 KEY: 71360800000081147 INDEX: 4
60  [5] RUN: 7136080 EVENT: 81155 KEY: 71360800000081155 INDEX: 5
61  [6] RUN: 7136080 EVENT: 81166 KEY: 71360800000081166 INDEX: 6
62  [7] RUN: 7136080 EVENT: 81170 KEY: 71360800000081170 INDEX: 7
63  [8] RUN: 7136080 EVENT: 81195 KEY: 71360800000081195 INDEX: 8
64  [9] RUN: 7136080 EVENT: 81198 KEY: 71360800000081198 INDEX: 9
65 
66  */
67 
68  Int_t tryRuns[] = { 7136073, 7136073, 7136073, 7136080, 7136080, 7136080 };
69  Int_t tryEvents[] = { 2721, 3548, 25769, 81133, 81155, 81198 };
70 
71  for ( Int_t ii=0;ii< sizeof(tryRuns)/sizeof(Int_t);ii++ )
72  {
73 
74  if ( !reader->getEvent( tryRuns[ii], tryEvents[ii] ) )
75  {
76  std::cout << Form("run %i event %i does not seem to exist",tryRuns[ii], tryEvents[ii]) << std::endl;
77  }
78  else
79  {
80  std::cout << Form("run %i event %i exists and is ready to be used ",tryRuns[ii], tryEvents[ii]) << std::endl;
81  StGammaEvent *event = reader->event();
82  // event->Print();
83  }
84 
85  }
86 
87 }
88 
89 
90 
91 // ----------------------------------------------------------------------------
92 //
93 // path: directory containing a group of root files
94 // filt: extention of files which are to be chained
95 //
96 void chainFiles(const Char_t *path, const Char_t *filt=".root")
97 {
98  std::cout << std::endl;
99  std::cout << "*************************************************************************" << std::endl;
100  std::cout << std::endl;
101  std::cout << "Chaining: " << path << std::endl;
102  std::cout << std::endl;
103  std::cout << "*************************************************************************" << std::endl;
104  std::cout << std::endl;
105  TString pwd = gSystem->pwd();
106  TSystemDirectory dir("dir",path);
107  TIter next( dir.GetListOfFiles() );
108  Int_t nn=0;
109  TObject *file = 0;
110  while ( file = (TObject*)next() )
111  {
112  TString name=path;name+=file->GetName();
113  if ( name.Contains(filt) ) {
114  reader->chainFile( name );
115  nn++;
116  }
117 
118  }
119  gSystem->cd(pwd.Data());
120 }
121 // ----------------------------------------------------------------------------
void chainFile(const Char_t *name, const Char_t *matches=".root")
Add a file to the list of files in the chain being processed.
Int_t getEvent(Long64_t entry)
Loads the specified entry in the chain. Access using event() defined above.