StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHiBaseAnalysis.cxx
1 #include "StHiBaseAnalysis.h"
2 
3 //__________________
4 
5 StHiBaseAnalysis::StHiBaseAnalysis(const char* inDir, const char* outRootName)
6  : mInputDir(inDir),mOutRootName(outRootName),
7  mNEvent(0), mNFile(0),
8  mDebug(0), mNEventAccepted(0),
9  mNHiPtTrack(0)
10 
11 {
12  mHiMicroChain = 0;
13  mHiMicroEvent = 0;
14  mOutRootFile = 0;
15  mBenchmark=0;
16 }
17 
18 //__________________
19 
20 StHiBaseAnalysis::~StHiBaseAnalysis()
21 {
22  mHiMicroChain = 0;
23  mHiMicroEvent = 0;
24  mOutRootFile = 0;
25  delete mBenchmark; mBenchmark=0;
26 }
27 
28 //__________________
29 //
30 // reads in all the files in the directory
31 // by default, looks for files ending in minimc.root
32 //
33 
34 Int_t
35 StHiBaseAnalysis::Init()
36 {
37  mBenchmark = new TBenchmark();
38  mBenchmark->Start("timer");
39 
40  Int_t stat=0;
41 
42  cout << "n event : " << mNEvent << endl;
43 
44  Cut::ShowCuts();
45 
46  cout << "init more" << endl;
47  stat += initMore();
48 
49  cout << "debug : " << mDebug << endl << endl;
50 
51  initChain();
52 
53  // create the output file
54  //
55  cout << "\nOutput file = " << mOutRootName << endl;
56  mOutRootFile = new TFile(mOutRootName.Data(),"RECREATE");
57  if(!mOutRootFile) {
58  cout << "Cannot open output root file " << mOutRootName << endl;
59  stat++;
60  }
61 
62  // init the histograms after the Tfile
63  //
64  initHistograms();
65 
66  return stat;
67 }
68 
69 //_________________
70 
71 Int_t StHiBaseAnalysis::initMore()
72 {
73  return 0;
74 
75 }
76 //_________________
77 
78 
79 void
80 StHiBaseAnalysis::initChain()
81 {
82  cout << "StHiBaseAnalysis::initChain()" << endl;
83  //
84  // create the chain and event
85  //
86  // add the files to the chain
87  //
88  mHiMicroChain = new TChain("StHiMicroTree");
89  mHiMicroEvent = new StHiMicroEvent;
90 
91  //
92  // set the address where to read the event object
93  //
94  mHiMicroChain->SetBranchAddress("StHiMicroEvent",&mHiMicroEvent);
95 
96  IO io(mInputDir.Data(),"hipico.root");
97  io.setNFile(mNFile);
98  io.chain(mHiMicroChain);
99 
100 }
101 //______________________
102 
103 void
104 StHiBaseAnalysis::Run()
105 {
106  if(mDebug)
107  cout << "StHiBaseAnalysis::Run()" << endl;
108 
109  //
110  // loop over all events
111  //
112  Int_t nEvent = (Int_t) mHiMicroChain->GetEntries();
113 
114  if(mNEvent && mNEvent<nEvent) nEvent = mNEvent;
115 
116  mNEvent = nEvent;
117 
118  cout << "Total # of events " << nEvent << endl;
119 
120  // turn of debug automatically for large number of events
121  //
122  if(nEvent>10000) mDebug = 0;
123 
124  Int_t display = 1000;
125 // Int_t display = 10000;
126 
127  for(Int_t iEvent=0; iEvent<nEvent; iEvent++){
128 
129  //
130  // read the event into memory
131  //
132  mHiMicroChain->GetEvent(iEvent);
133 
134  if(mHiMicroEvent){
135  if(iEvent%display==0){
136  cout << "--------------------- event " << iEvent
137  << "--------------------- " << endl;
138  cout << "\tprimary vertex z : " << mHiMicroEvent->VertexZ() << endl;
139  cout << "\tflow centrality : " << mHiMicroEvent->Centrality() << endl;
140  cout << "\tL0TriggerWord : " << mHiMicroEvent->L0TriggerWord() << endl;
141  if(mHiMicroEvent->L3UnbiasedTrigger())
142  cout << "\tL3UnbiasedTrigger Event " << endl;
143  if (mHiMicroEvent->L3RichTrigger())
144  cout << "\tL3RichTrigger Event " << endl;
145 
146  }
147 
148  //This comes before we make event cuts
149  fillEventHistograms();
150 
151  //
152 
153  if(acceptEvent(mHiMicroEvent)){
154 
155  mNEventAccepted++;
156 
157  if(iEvent%display==0) cout << "\tAccepted event" << endl;
158 
159  //Standard event cut on vertexZ, centrality and triggerword are already done
160  trackLoop();
161  }
162  else{
163  if(iEvent%display==0) cout << "\tNot Accepted " << endl;
164  }
165  }
166  else{ // couldnt read the event??
167  cout << "##Cannot process event." << endl;
168  }
169  mHiMicroEvent->Clear();
170  }
171 }
172 
173 //_____________________
174 
175 void
176 StHiBaseAnalysis::trackLoop()
177 {
178  if(mDebug)
179  cout << "StHiBaseAnalysis::trackLoop()" << endl;
180 
181  Int_t nTrack = mHiMicroEvent->NTrack();
183 
184  for(Int_t i=0; i<nTrack; i++){
185  track =(StHiMicroTrack*) mHiMicroEvent->tracks()->At(i);
186 
187  } // tracks
188 
189  if(mDebug)
190  cout << "\ttracks : " << nTrack << endl;
191 
192 }
193 //_____________________
194 
195 void
196 StHiBaseAnalysis::fillEventHistograms()
197 {
198 
199 }
200 
201 //_______________________
202 
203 void
204 StHiBaseAnalysis::initHistograms()
205 {
206 
207 }
208 
209 //_______________________
210 
211 Bool_t
212 StHiBaseAnalysis::trackOk(StHiMicroTrack* track)
213 {
214  if(!track) {
215  cout << "No track pointer?" << endl;
216  return kFALSE;
217  }
218  return kTRUE;
219 }
220 
221 //_______________________
222 
223 void
224 StHiBaseAnalysis::Finish()
225 {
226  cout << "###StHiBaseAnalysis::Finish" << endl;
227 
228  cout << "\tall : " << mNEvent << endl;
229  cout << "\taccepted: " << mNEventAccepted << endl;
230 
231  finishHistograms();
232 
233  cout << "\tWriting " << mOutRootName << endl;
234  mOutRootFile->Write();
235  mOutRootFile->Close();
236  cout << "\tDone" << endl;
237 
238  mBenchmark->Show("timer");
239 
240 }
241 //______________________
242 
243 void
244 StHiBaseAnalysis::finishHistograms()
245 {
246 }
247 
248 //_______________________
249 
250 Bool_t
251 StHiBaseAnalysis::acceptEvent(StHiMicroEvent* event)
252 {
253  return CutRc::Accept(event);
254 
255 }
256 
257 //_____________________________________
258 
259 ClassImp(StHiBaseAnalysis)
Definition: IO.h:20