StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doEStructWrite.C
1 
2 void doEStruct( const char* filelist,
3  const char* outputDir,
4  const char* scriptDir,
5  int maxNumEvents = 1000 ) {
6 
7  // I have taken a standard doEStruct.C macro and stripped it as much as I
8  // could so it only reads MuDst events, applies event and track cuts while
9  // converting to EStructEvent, then write out the EStructEvent.
10  char cutFile[1024];
11  sprintf(cutFile,"%s/CutsFile.txt",scriptDir);
12  const char* jobName = "AuAu200_2011_StEStructEventTest";
13 
14  gROOT->LoadMacro("load2ptLibs.C");
15  load2ptLibs();
16  gROOT->LoadMacro("getOutFileName.C");
17  gROOT->LoadMacro("support.C");
18 
19  bool useGlobalTracks = false;
20  // Need an EStruct maker.
21  char *analysisType = "StEStructCorrelation";
22  StEStructAnalysisMaker *estructMaker = new StEStructAnalysisMaker(analysisType);
23 
24  // Set up the Analysis codes and initialize the cuts.
25  StEStructEventCuts* ecuts = new StEStructEventCuts(cutFile);
26  StEStructTrackCuts* tcuts = new StEStructTrackCuts(cutFile);
27 
28 
29  // reader = reader interface + pointer to Data Maker + cut classes
30  StMuDstMaker* mk = new StMuDstMaker(0,0,"",filelist,".",500);
31  StEStructMuDstReader* reader = new StEStructMuDstReader(mk,ecuts,tcuts);
32  reader->setUseGlobalTracks(useGlobalTracks);
33  estructMaker->SetEventReader(reader);
34 
35  // create the QAHist object (must come after centrality and cutbin objects)
36  // QA histograms include centrality class definitions and occupancies.
37  // These can be re-defined in the macro that analyzes EStructEvents.
38  StEStructCentrality* cent=StEStructCentrality::Instance();
39  const double mbBins[] = {2, 15, 35, 68, 117, 187, 281, 401, 551, 739, 852, 1002};
40  int mbNBins = 12;
41  cent->setCentralities(mbBins,mbNBins);
42  int EventType = 0;
43  StEStructQAHists* qaHists = new StEStructQAHists(EventType);
44  estructMaker->SetQAHists(qaHists);
45 
46  // Put special processing that needs to be done before the event loop here.
47  TChain *ch = mk->chain();
48  int nEvents = ch->GetEntries();
49  cout << "Total number of events in chain = " << nEvents << endl;
50 
51  ch->SetBranchStatus("*",0);
52  ch->SetBranchStatus("MuEvent.*",1);
53  ch->SetBranchStatus("PrimaryTracks.*",1);
54  ch->SetBranchStatus("GlobalTracks.*",1);
55  if (ch->GetBranch("PrimaryVertices")) {
56  ch->SetBranchStatus("PrimaryVertices.*",1);
57  }
58  ecuts->setDoFillHists(true);
59  tcuts->setDoFillHists(true);
60 
61  StEStructEvent *ev;
62  int igood = 0;
63  int iev = 0;
64  bool done = false;
65  TTimeStamp TS;
66  int startTime = TS.GetSec();
67  char *outFile = getOutFileName(outputDir,jobName,"EStruct");
68  cout << " getOutFileName(outputDir,jobName,\"EStruct\") = " << outFile << endl;
69  TFile *fESOut = new TFile(outFile,"RECREATE");
70  while (!done) {
71  // This simply reads an event and fills a StEStructEvent object,
72  // applying cuts. If event fails ev will be NULL;
73  iev++;
74  ev = reader->next();
75  done = reader->done();
76  if ((iev%1000) == 0) {
77  TTimeStamp TS;
78  cout << "Found " << igood << " events after scanning " << iev << ". Has been " << TS.GetSec()-startTime << " seconds since start of scan loop." << endl;
79  }
80  if (!ev) {
81  continue;
82  }
83  igood++;
84  TString evName("EStructEvent"); evName += iev;
85  ev->Write(evName.Data());
86  delete ev;
87  if ((maxNumEvents!=0) && (iev>=maxNumEvents)) {
88  done = true;
89  }
90  }
91  fESOut->Close();
92 
93  // --> statistics file
94  char *statsFile = getOutFileName(outputDir,jobName,"stats");
95  cout << "getOutFileName(outputDir,jobName,\"stats\") = " << statsFile << endl;;
96  ofstream ofs(statsFile);
97  estructMaker->logAllStats(ofs);
98  ecuts->printCuts(ofs);
99  ecuts->printCutStats(ofs);
100  tcuts->printCuts(ofs);
101  tcuts->printCutStats(ofs);
102  ofs<<endl;
103  ofs.close();
104 
105  // --> root cut histogram file
106  char *cutsFile = getOutFileName(outputDir,jobName,"cuts");
107  cout << "getOutFileName(outputDir,jobName,\"cuts\") = " << cutsFile << endl;
108  TFile *tfc = new TFile(cutsFile,"RECREATE");
109  ecuts->writeCutHists(tfc);
110  tcuts->writeCutHists(tfc);
111  tfc->Close();
112 
113  // --> root QA histogram file
114  char *qaFile = getOutFileName(outputDir,jobName,"QA");
115  cout << "getOutFileName(outputDir,jobName,\"QA\") = " << qaFile << endl;
116  estructMaker->writeQAHists(qaFile);
117 
118 }
TChain * chain()
In read mode, returns pointer to the chain of .MuDst.root files that where selected.
Definition: StMuDstMaker.h:426