StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RunPythiaReader.C
1 
2 // NOTE - chain needs to be declared global so for StHbtEventReader
3 //=========================================================================================
4 class StChain;
5 StChain *chain;
6 int total=0;
7 
8 void RunPythiaReader(int nevents=10,
9  const char* jetInFile = "processed/pds1214_23_5000evts.jet.root"
10  )
11 {
12  cout <<"read jet file:\t"<<jetInFile<<endl;
13 
14  string basename = firstHalf(jetInFile,"/processed/",".jet.root");
15  cout <<"basename:\t"<<basename<<endl;
16  TString ofn = TString("./assoc/") + TString(basename) + TString(".assoc.root");
17  const char* outfile = ofn.Data();
18  cout <<"write assoc file:\t"<<outfile<<endl;
19 
20  if (gClassTable->GetID("TTable") < 0) {
21  gSystem->Load("libStar");
22  gSystem->Load("libPhysics");
23  }
24  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
25  loadSharedLibraries();
26  gSystem->Load("StMagF");
27  gSystem->Load("StTpcDb");
28  gSystem->Load("StDbUtilities");
29  gSystem->Load("StMcEvent");
30  gSystem->Load("StMcEventMaker");
31  gSystem->Load("StDaqLib");
32  gSystem->Load("StEmcRawMaker");
33  gSystem->Load("StEmcADCtoEMaker");
34  gSystem->Load("StEmcUtil");
35  gSystem->Load("StDbLib");
36  gSystem->Load("StDbBroker");
37  gSystem->Load("St_db_Maker");
38  gSystem->Load("StEEmcUtil");// needed by EEMC-Db
39  gSystem->Load("StEEmcDbMaker");
40  gSystem->Load("StJetFinder");
41  gSystem->Load("StJetMaker");
42 
43  double pi = atan(1.0)*4.0;
44  cout << " loading done " << endl;
45 
46  chain= new StChain("StChain");
47  chain->SetDebug(1);
48 
49  //Instantiate the JetReader
50  StJetReader* jetReader = new StJetReader("JetReader",0);
51 
52  StPythiaAssociator* jetAssoc = new StPythiaAssociator("JetAssoc", outfile, jetReader);
53 
54  chain->PrintInfo();
55  chain->Init();
56 
57  jetReader->InitFile(jetInFile);
58 
59  int ntotal = jetReader->tree()->GetEntries();
60 
61  chain->PrintInfo();
62 
63  for (Int_t iev=0;iev<nevents && iev<ntotal; iev++) {
64  cout << "****************************************** " << endl;
65  cout << "Working on eventNumber " << iev << endl;
66  cout << "*************************1***************** " << endl;
67  chain->Clear();
68  int iret = chain->Make(iev);
69  total++;
70  if (iret) {
71  cout << "Bad return code!" << endl;
72  break;
73  }
74  }
75 
76  chain->Finish();
77  cout << "****************************************** " << endl;
78  cout << "total number of events " << total << endl;
79  cout << "****************************************** " << endl;
80 }
81 
82 string firstHalf(string infile, string begin, string end, int offset=0)
83 {
84  cout <<"look for:\t"<<begin<<"\tin:\t"<<infile<<endl;
85  unsigned int where1 = infile.find(begin);
86  cout <<"look for:\t"<<end<<"\tin:\t"<<infile<<endl;
87  unsigned int where2 = infile.find(end);
88  if (where2==infile.npos) {
89  return 0;
90  }
91 
92  int start=where1+begin.size()+offset;
93  int stop=where2;
94  if (stop<=start) {
95  cout <<"error, mismatch.abort()"<<endl; abort();
96  }
97  //cout <<"numbers of events is between indices: ["<<start<<","<<stop<<")"<<endl;
98  string number;
99  for (int i=start; i<stop; ++i) {
100  //cout <<"\ti:\t"<<i<<"\t"<<infile[i]<<endl;
101  number += infile[i];
102  }
103  return number;
104 }
105 
virtual void InitFile(const char *file)
Recover the TTree from file and prepare for reading.
Definition: StJetReader.cxx:61
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
TTree * tree() const
Access to the StJets tree.
Definition: StJetReader.h:65
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual Int_t Make()
Definition: StChain.cxx:110