StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DoSt2feeTTree.C
1 //
3 // $Id: DoSt2feeTTree.C,v 1.8 2009/02/04 20:33:30 ogrebeny Exp $
4 //
5 // Description:
6 // Chain to read events from files or database into StEvent and analyze.
7 // what it does: reads .dst.root or .xdf files and then runs StEventMaker
8 // to fill StEvent and StAnalysisMaker to show example of analysis
9 //
10 // Environment:
11 // Software developed for the STAR Detector at Brookhaven National Laboratory
12 //
13 // Ways to run:
14 // If you specify a path, all DST files below that path will be
15 // found, and the first 'nEvents' events in the file set will be
16 // analyzed.
17 // The type of DST files searched for is taken from the 'file' parameter.
18 // If 'file ends in '.dst.root', ROOT DSTs are searched for.
19 // If 'file ends in '.xdf', XDF DSTs are searched for.
20 //
21 // If path begins with '-', 'file' will be taken to be a single file
22 // to be processed.
23 //
24 // example invocation:
25 // .x doEvents.C(10,"some_directory/some_dst_file.xdf")
26 //
27 // example ROOT file invocation:
28 // .x doEvents.C(10,"some_directory/some_dst_file.root")
29 //
30 // example multi-ROOT file invocation:
31 // .x doEvents.C(9999,"some_directory/*.dst.root")
32 //
34 //
35 // Author List: Torre Wenaus, BNL 2/99
36 // Victor Perevoztchikov
37 //
38 // inputs:
39 // nEvents = # events to process
40 // path = a. directory you want files from
41 // b. "-" to get just the one file you want
42 // file = a. file names in directory (takes all files)
43 // b. the 1 particular full file name (with directory) you want
44 // qaflag = "evout" turn on writing of output test.event.root
45 // qaflag = "display" turn on EventDisplay
46 // file --- set to off by default
47 //
49 
50 #include "iostream.h"
51 
52 class StChain;
53 StChain *chain=0;
54 class St_db_Maker;
55 St_db_Maker *dbMk =0;
56 
57 Int_t iEvt=0,istat=0,nEvents=0;
58 void doEvents()
59 {
60  cout << "Usage: doEvents.C(2) // work with default event.root file" << endl;
61  cout << " doEvents.C(startEvent,nEvents,\"path/somefile.event.root\")" << endl;
62  cout << " doEvents.C(nEvents,\"path/*.event.root\")" << endl;
63  cout << " doEvents.C(nEvents,\"path/file.dst.root\",\"evout\") //Write out StEvent" << endl;
64  cout << " doEvents.C(nEvents,\"path/file.dst.root\",\"display\") //EventDispay" << endl;
65  cout << " doEvents.C(nEvents,\"path/file.dst.root\",\"dbon\") //DB on" << endl;
66 }
67 // ProtoTypes
68 
69 void doEvents(Int_t nEvents, const Char_t ** fileList, const Char_t *qaflag =0);
70 void doEvents(Int_t startEvent, Int_t nEvents, const Char_t ** fileList, const Char_t *qaflag =0);
71 
72 void doEvents(Int_t nEvents,
73  const Char_t *file="st_physics_4095050_raw_0010002.event.root",
74  const Char_t *qaflag = "dbon");
75 
76 void doEvents(Int_t startEvent,Int_t nEvents,
77  const Char_t *file="/afs/rhic.bnl.gov/star/data/samples/example.event.root",
78  const Char_t *qaflag = 0);
79 
80 void doEvents(const Int_t nEvents,
81  const Char_t *path,
82  const Char_t *file,
83  const Char_t *qaflag, int flag);
84 
85 
86 
87 
88 // ------------------ Here is the actual method -----------------------------------------
89 void doEvents(Int_t startEvent, Int_t nEventsQQ, const Char_t **fileList, const Char_t *qaflag)
90 {
91 
92  nEvents = nEventsQQ;
93  TString tflag = qaflag; tflag.ToLower();
94  int eventDisplay = tflag.Contains("disp");
95 
96  cout << endl << endl <<" doEvents - input # events = " << nEvents << endl;
97  Int_t ilist=0;
98  while(fileList[ilist]){
99  cout << " doEvents - input fileList = " << fileList[ilist] << endl;
100  ilist++;
101  }
102  cout << " doEvents - input qaflag = " << qaflag << endl;
103 
104  //
105  // First load some shared libraries we need
106  //
107  gSystem->Load("libStar");
108  gSystem->Load("St_base");
109  gSystem->Load("StChain");
110 
111  gSystem->Load("libgen_Tables");
112  gSystem->Load("libsim_Tables");
113  gSystem->Load("libglobal_Tables");
114 
115  gSystem->Load("StUtilities");
116  gSystem->Load("StIOMaker");
117  gSystem->Load("StTreeMaker");
118  gSystem->Load("StarClassLibrary");
119  gSystem->Load("StTriggerDataMaker");
120  gSystem->Load("StEvent");
121  gSystem->Load("StEventUtilities");
122  gSystem->Load("StMagF");
123  gSystem->Load("StAnalysisMaker");
124 
125 
126  // DB ON
127  if (tflag.Contains("dbon") || eventDisplay ) {
128  gSystem->Load("libtpc_Tables");
129  gSystem->Load("StDbLib.so");
130  gSystem->Load("StDbBroker.so");
131  gSystem->Load("libStDb_Tables.so");
132  gSystem->Load("St_db_Maker.so");
133  gSystem->Load("StTpcDb");
134  gSystem->Load("StDetectorDbMaker");
135  }
136 
137  // Special libraries for EventDisplay
138  if (eventDisplay) {//EventDisplay on
139  gSystem->Load("St_g2t");
140  gSystem->Load("geometry");
141  gSystem->Load("St_geant_Maker");
142  gSystem->Load("StTableUtilities");
143  gSystem->Load("StEventDisplayMaker");
144  }
145 
146  //
147  // Handling depends on whether file is a ROOT file or XDF file
148  //
149  chain = new StChain("StChain");
150  StFileI *setFiles =0;
151  if (fileList) { //Normal case
152  setFiles= new StFile(fileList);
153  } else { //Grand Challenge
154  gSystem->Load("StChallenger");
155  setFiles = StChallenger::Challenge();
156  setFiles->SetDebug();
157  const char *Argv[]= {
158  "-s","dst runco", // list of components needed
159  "-q","numberOfPrimaryTracks>1500", // example of user query
160  "-c","/afs/rhic.bnl.gov/star/incoming/GCA/daq/stacs.rc" // pointer to GC servers for daq
161  };
162  Int_t Argc=sizeof(Argv)/4;
163  setFiles->Init(Argc,Argv);
164  }
165 
166 // Geant maker for EventDisplay
167  if (eventDisplay) {
168  int NwGeant=5000000, IwType=0, NwPaw=0;
169  St_geant_Maker *geantMk = new St_geant_Maker("geant",NwGeant,NwPaw,IwType);
170  geantMk->LoadGeometry("detp geometry year2001");
171  geantMk->SetActive(kFALSE);
172  }
173 
174 
175  TString mainBranch;
176  if (fileList && fileList[0]) {
177  char line[999]; strcpy(line,fileList[0]);
178  if (*line=='@') {
179  TString command("grep '.root' "); command += line+1;
180  FILE *pipe = gSystem->OpenPipe(command.Data(),"r");
181  if (pipe) {fgets(line,999,pipe);line[strlen(line)-1] = 0;}
182  fclose(pipe);
183  }
184  mainBranch = line;
185 // printf("fileList[0] %s %s\n",line,mainBranch.Data());
186  mainBranch.ReplaceAll(".root","");
187  int idot = strrchr((char*)mainBranch,'.') - mainBranch.Data();
188  mainBranch.Replace(0,idot+1,"");
189  mainBranch+="Branch";
190  printf("*** mainBranch=%s ***\n",mainBranch.Data());
191  }
192 
193  StIOMaker *IOMk = new StIOMaker("IO","r",setFiles,"bfcTree");
194  IOMk->SetIOMode("r");
195  IOMk->SetBranch("*",0,"0"); //deactivate all branches
196  if(!mainBranch.IsNull()) IOMk->SetBranch(mainBranch,0,"r");
197  IOMk->SetBranch("evtselBranch",0,"r");
198  // IOMk->SetBranch("dstBranch",0,"r");
199 // IOMk->SetBranch("runcoBranch",0,"r");
200  IOMk->SetDebug(1);
201 //for test only IOMk->SetMaxEvent(2);
202 
203 // DB ON
204  if (tflag.Contains("dbon")) {
205  dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb","StarDb");
206  }
207 
208  //
209  // Maker to read events from file or database into StEvent
210  //
211  if (mainBranch.Contains("dstBranch")) {
212  gSystem->Load("StEventMaker");
213  StEventMaker *readerMaker = new StEventMaker("events","title");
214  }
215  //
216  // Sample analysis maker
217  //
218  StAnalysisMaker *analysisMaker = new StAnalysisMaker("analysis");
219  gSystem->Load("StEEmcDbMaker");
220  gSystem->Load("StEEmcUtil");
221 // My Makers 1
222  StEEmcDbMaker *myMk1=new StEEmcDbMaker("eemcDBio");
223  // myMk1->setDBname("TestScheme/emc");
224  myMk1->setSectors(1,12);
225  myMk1->setTimeStampDay(20030214); // format: yyyymmdd
226 
227 
228  St_db_Maker *dbMk = new St_db_Maker("StarDb","MySQL:StarDb");
229 
230  // My Makers 2
231  St2eemcFeeRawMaker * myMk3=new St2eemcFeeRawMaker("St2feeTTree");
232 // myMk3->setDb(myMk1);
233  char *fileT="myOut.eeTree.root"; // output TTree
234 
235  // Output TTree
236  TFile f(fileT,"RECREATE");
237  TTree t("fee","A tree with FEE events"); // define branch
238  myMk3->setOutTTree(&t);
239 
241 // IT IS THE PLACE TO ADD USER MAKERS
242 // LIKE:
243 // gSystem->Load("StUserMaker");
244 // StUserMaker *UserMk = new StUserMaker("UserName");
245 // UserMk->SetSome(2002);
247  // WriteOut StEvent
248  Int_t wrStEOut = tflag.Contains("evout");
249  if (wrStEOut) {
250  cout << "!!!! doEvents: will write out .event.root file !!" << endl << endl;
251  StIOMaker *outMk = new StIOMaker("EvOut","w","test.event.root","bfcTree");
252 // outMk->SetBranch("eventBranch","test.event.root","w");
253  outMk->IntoBranch("evtselBranch","StEvent");
254  IOMk->SetNotify("CloseFile",outMk);
255  IOMk->SetNotify("OpenFile" ,outMk);
256  }
257 
258 
259 // StEventDisplayMaker
260  if (eventDisplay) {
261 
262  StEventDisplayMaker *displayMk = new StEventDisplayMaker();
263 
264  // Set the default to display all StEvent tracks
265  displayMk->AddName("StEvent(Primary Tracks)");
266  displayMk->AddName("StEvent(Kink Tracks)");
267  displayMk->AddName("StEvent(V0 Tracks)");
268  displayMk->AddName("StEvent(Xi Tracks)");
269  // displayMk->AddName("StEvent(All Tracks)");
270  // Set the default StEvent events filter
271  displayMk->AddFilter(new StFilterDef("MainFilter"));
272  displayMk->AddFilter(new StMuDstFilterHelper("MuL3Filter",kFALSE));
273  }
274 
275  //
276  // Initialize chain
277  //
278  Int_t iInit = chain->Init();
279  if (iInit) chain->Fatal(iInit,"on init");
280  chain->PrintInfo();
281  if (startEvent > 1) IOMk->Skip(startEvent-1);
282 
283 
284 
285 //----- added 6/20/00 by Kathy
286  TTable *tabl=0;
287  TDataSet *obj=0;
288  TDataSet *ddb=0;
289  TDataSet *ddstBranch=0;
290 //------
291 
292  //
293  // Event loop
294  //
295  istat=0,iEvt=1;
296 
297  int eventCounter=0;
298  int stat=0;
299  //---------------------------------------------------
300  while ( stat==0 ) {// loop over events
301  if(eventCounter>=nEvents) break;
302  chain->Clear();
303  stat = chain->Make();
304 
305  printf(" event# %d\n", eventCounter++);
306 
307  }
308  // istat = chain->EventLoop(1,nEvents);
309  //JB t.Print();
310 
311  f.Write();
312  printf("\n\n============== TTree closed =========\n\n");
313 
314 
315 }
316 
317 //--------------------------------------------------------------------------
318 
319 void doEvents(const Int_t startEvent, const Int_t nEvents, const Char_t *file, const Char_t *qaflag)
320 {
321  printf("*file = %s\n",file);
322  const char *fileListQQ[]={0,0};
323  if (strncmp(file,"GC",2)==0) {
324  fileListQQ=0;
325  } else {
326  fileListQQ[0]=file;
327  }
328  doEvents(startEvent,nEvents,fileListQQ,qaflag);
329 }
330 //--------------------------------------------------------------------------
331 void doEvents(const Int_t nEvents, const Char_t *file, const Char_t *qaflag)
332 {
333  doEvents(1,nEvents,file,qaflag);
334 }
335 
336 //--------------------------------------------------------------------------
337 void doEvents(const Int_t nEvents, const Char_t *path,const Char_t *file, const Char_t *qaflag, int flag)
338 {
339  TString F;
340  if (path && path[0] && path[0]!='-') F = path;
341  if (file && file[0] && file[0]!='-')
342  {
343  if (!F.IsNull()) F +="/";
344  F += file;
345  }
346  TString opt = qaflag;
347  if (flag) opt += " evout";
348 
349 
350  doEvents(1,nEvents,F.Data(),opt.Data());
351 }
352 
353 //--------------------------------------------------------------------------
354 void doEvents(Int_t nEvents, const Char_t **fileList, const Char_t *qaflag)
355 { doEvents(1,nEvents,fileList,qaflag); }
356 
Definition: StTree.h:125
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
void setOutTTree(TTree *t)
TTree must be initialized externaly.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
A typical Analysis Class.
virtual Int_t Make()
Definition: StChain.cxx:110
Definition: TTable.h:48
virtual void SetActive(Bool_t k=kTRUE)
Setters for flags and switches.
Definition: StMaker.h:208
virtual void LoadGeometry(const Char_t *option="detp geometry field_only")
Specifies GEANT3 geometry command.