StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doEStructRead.C
1 
2 void doEStructRead( const char* inputfile,
3  const char* outputDir,
4  const char* scriptDir,
5  int maxNumEvents = 1000 ) {
6 
7  char cutFile[1024];
8  sprintf(cutFile,"%s/CutsFile.txt",scriptDir);
9  const char* jobName = "ReadEStruct";
10 
11  gROOT->LoadMacro("load2ptLibs.C");
12  load2ptLibs();
13  gROOT->LoadMacro("getOutFileName.C");
14  gROOT->LoadMacro("support.C");
15 
16  StEStructCentrality* cent=StEStructCentrality::Instance();
17  const double mbBins[] = {2, 15, 35, 68, 117, 187, 281, 401, 551, 739, 852, 1002};
18  int mbNBins = 12;
19  cent->setCentralities(mbBins,mbNBins);
20 
21  // >>>>>>Check: Probably want to keep ZBuffers for central bins. I won't bother for testing though.
22  const int mkeepZBuffBins[] = {0};
23  int mNZBufs = 1;
24  int cutBinMode = 3;
25  int analysisMode = 0x60;
26 
27  // choose the mode for the binning
28  int numberOfAnalyses = mbNBins-1;
29  StEStructCutBin* cb=StEStructCutBin::Instance();
30  cb->setMode(cutBinMode);
31  StEStruct2ptCorrelations** analysis = new StEStruct2ptCorrelations*[numberOfAnalyses];
32 
33  StEStructPairCuts* pcuts = new StEStructPairCuts(cutFile);
34 
35  // Need an EStruct maker.
36  char *analysisType = "StEStructCorrelation";
37  StEStructAnalysisMaker *estructMaker = new StEStructAnalysisMaker(analysisType);
38 
39  StEStructEventCuts* ecuts = new StEStructEventCuts(cutFile);
40  StEStructTrackCuts* tcuts = new StEStructTrackCuts(cutFile);
41  StEStructEventReader* reader = new StEStructEStructReader(inputfile,ecuts,tcuts);
42  estructMaker->SetEventReader(reader);
43 
44  int EventType = 0;
45  StEStructQAHists* qaHists = new StEStructQAHists(EventType);
46  estructMaker->SetQAHists(qaHists);
47 
48  // build the numberOfAnalyses readers and numberOfAnalyses analysis objects
49  // analysis = analysis interface and contains pair-cut object (needs file)
50  for(int i=0;i<numberOfAnalyses;i++) {
51 
52  analysis[i] = new StEStruct2ptCorrelations(pcuts,analysisMode);
53 // analysis[i]->setZBuffLimits(ecuts);
54  analysis[i]->setAnalysisIndex(i);
55  analysis[i]->setOutputFileName(getOutFileName(outputDir,jobName,"data",i));
56  analysis[i]->setQAHists(qaHists);
57  if ((mNZBufs == numberOfAnalyses) && (0 != mkeepZBuffBins[i])) {
58  analysis[i]->setZBufferBinning(1);
59  }
60 
61 
62  }
63  estructMaker->SetAnalyses(analysis,numberOfAnalyses);
64  estructMaker->Init();
65 
66  ecuts->setDoFillHists(true);
67  tcuts->setDoFillHists(true);
68 // How do we get number of events in advance?
69 // cout << "Total number of events in file = " << nEvents << endl;
70  int iev = 0;
71  int istat = 0;
72  TTimeStamp TS;
73  int startTime = TS.GetSec();
74  while (istat != 2) {
75  istat = estructMaker->Make();
76  iev++;
77  if ((iev%200) == 0) {
78  TTimeStamp TS;
79  cout << "Analysed " << iev << " events in " << TS.GetSec()-startTime << " seconds." << endl;
80  }
81  if ((maxNumEvents> 0) && (iev >= maxNumEvents)) {
82  break;
83  }
84  }
85  TTimeStamp TS;
86  cout << "Seconds for entire event loop = " << TS.GetSec()-startTime << endl;
87 
88 
89  // If special processing needs clean up put code here.
90 
91 
92 
93  // --> statistics file
94  ofstream ofs(getOutFileName(outputDir,jobName,"stats"));
95  estructMaker->logAllStats(ofs);
96  ecuts->printCuts(ofs);
97  ecuts->printCutStats(ofs);
98  tcuts->printCuts(ofs);
99  tcuts->printCutStats(ofs);
100  pcuts->printCuts(ofs);
101  ofs<<endl;
102  ofs.close();
103 
104  // --> root cut histogram file
105  char *cutsFile = getOutFileName(outputDir,jobName,"cuts");
106  cout << "getOutFileName(outputDir,jobName,\"cuts\") = " << cutsFile << endl;
107  TFile *tfc = new TFile(cutsFile,"RECREATE");
108  ecuts->writeCutHists(tfc);
109  tcuts->writeCutHists(tfc);
110  tfc->Close();
111 
112  // --> root QA histogram file
113  char *qaFile = getOutFileName(outputDir,jobName,"QA");
114  cout << "getOutFileName(outputDir,jobName,\"QA\") = " << qaFile << endl;
115  estructMaker->writeQAHists(qaFile);
116 
117  // --> Write out the data in the form of root histograms.
118  estructMaker->Finish();
119 }