StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructAnalysisMaker.cxx
1  /***************************************************************************
2  *
3  * $Id: StEStructAnalysisMaker.cxx,v 1.9 2012/11/16 21:19:05 prindle Exp $
4  *
5  *************************************************************************
6  *
7  * Description: This is a maker for general EStruct Analysis
8  * Requires at least 1 reader and 1 analysis
9  *
10  * 2 RULES:: Reader gives up event (creates new event)
11  * Analysis takes ownership of event (must delete!)
12  *
13  **************************************************************************/
14 
15 #include <stdlib.h>
16 #include <math.h>
17 #include "StEStructAnalysisMaker.h"
18 
19 #include "StEStructPool/EventMaker/StEStructEvent.h"
20 #include "StEStructPool/EventMaker/StEStructTrack.h"
21 #include "StEStructPool/EventMaker/StEStructCentrality.h"
22 
23 //for memory mangement
24 #include "StMemoryInfo.hh"
25 //#include "StMuTimer.h"
26 //
27 #include "StChain.h"
28 #include "TFile.h"
29 #include "StMessMgr.h"
30 
31 
32 ClassImp(StEStructAnalysisMaker)
33 
34 //--------------------------------------------------------------
35 StEStructAnalysisMaker::StEStructAnalysisMaker(const Char_t *name) : StMaker(name) {
36  mtimer=NULL;
37  mEventLoopCounter=0;
38  mreader=0;
39  manalysis[0]=0;
40  mEventProcessedCounter=0;
41  numAnalysis=0;
42  doPrintMemoryInfo=false;
43  mEventProcessedPerType=0;
44  doReactionPlaneAnalysis=false;
45  mQAHists = NULL;
46 }
47 
48 //--------------------------------------------------------------
49 StEStructAnalysisMaker::~StEStructAnalysisMaker() {
50 
51  for(int i=0;i<numAnalysis;i++) delete manalysis[i];
52  if(mtimer) delete mtimer;
53 
54 }
55 
56 //--------------------------------------------------------------
57 Int_t StEStructAnalysisMaker::Init()
58 {
59  // gMessMgr->Info() << "StEStructAnalysisMaker: Init()" << endm;
60  startTimer();
61 
62  if(!mreader || !numAnalysis){
63  gMessMgr->Error()<<" StEStructAnalysisMaker::Init() no reader ";
64  gMessMgr->Error()<<" Or no analysis object: Will Abort "<<endm;
65  assert(0);
66  }
67 
68  mEventProcessedPerType=new int[numAnalysis];
69  for(int i=0;i<numAnalysis;i++) mEventProcessedPerType[i]=0;
70 
71  return kStOK;
72 }
73 
74 //--------------------------------------------------------------
75 void
77 
78 //--------------------------------------------------------------
79 Int_t
81 {
82  if (doPrintMemoryInfo) {
83  StMemoryInfo::instance()->snapshot();
84  StMemoryInfo::instance()->print();
85  }
86  for(int i=0;i<numAnalysis;i++) manalysis[i]->finish();
87  if (mtimer) {
88  mtimer->stop();
89  }
90 
91  // Do Not Delete This --> if(mQAHists) delete mQAHists;
92 
93  return kStOk; // remove this .... StMaker::Finish();
94 }
95 
96 
97 //-----------------------------------------------------
98 Int_t
100 
101 
102  if (doPrintMemoryInfo)StMemoryInfo::instance()->snapshot();
103 
104  if(!mreader || !manalysis[0] ){
105  gMessMgr->Error()<<" No Reader in StEStructAnalysisMaker::Make() "<<endm;
106  return kStFatal;
107  }
108 
109  mEventLoopCounter++;
110  //
111 
113  // model: each reader has a different cut file for event selection.
114  // if event doesn't pass a reader's cut, there is a check
115  // for EOF and, if not, it goes to the next reader. If the event
116  // passes, then the analysis is run and the loop is broken
117  // Thus, an event can only be sent to 1 of the analysis modules.
118  //
119 
120  mCurrentAnalysis = 0;
121  if(!(pEStructEvent=mreader->next())){
122  if(mreader->done()) return kStEOF;
123  } else {
124  int ia = getAnalysisIndex(); // 0 if numAnalysis = 1
125  if (mSorting) {
126  return kStOK;
127  }
128  if(ia>=0 && ia < numAnalysis) {
129  if(doReactionPlaneAnalysis) {
130  pEStructEvent->SetPhiWgt(mWeightFile);
131  //pEStructEvent->SetPhiWgt();
132  pEStructEvent->ShiftPhi(); // This step modifies all Phi values to be w.r.t. the reaction plane
133  }
134 
135  manalysis[ia]->doEvent(pEStructEvent);
136  mEventProcessedCounter++;
137  mEventProcessedPerType[ia]++;
138  if(mQAHists)mQAHists->fillHistograms(pEStructEvent,mreader);
139  mCurrentAnalysis = manalysis[ia];
140  }
141  }
142 
143  if (doPrintMemoryInfo) {
144  StMemoryInfo::instance()->snapshot();
145  StMemoryInfo::instance()->print();
146  }
147 
148  return kStOK;
149 }
150 
151 //-----------------------------------------------------
153 
154 
155  if (doPrintMemoryInfo)StMemoryInfo::instance()->snapshot();
156 
157  if(!ev || !manalysis[0] ){
158  gMessMgr->Error()<<" No Reader in StEStructAnalysisMaker::Make() "<<endm;
159  return kStFatal;
160  }
161 
162  mEventLoopCounter++;
163  //
164 
166  // model: each reader has a different cut file for event selection.
167  // if event doesn't pass a reader's cut, there is a check
168  // for EOF and, if not, it goes to the next reader. If the event
169  // passes, then the analysis is run and the loop is broken
170  // Thus, an event can only be sent to 1 of the analysis modules.
171  //
172 
173  mCurrentAnalysis = 0;
174  pEStructEvent = ev;
175 
176  int ia = getAnalysisIndex(); // 0 if numAnalysis = 1
177  if (mSorting) {
178  return kStOK;
179  }
180  if(ia>=0 && ia < numAnalysis) {
181  if(doReactionPlaneAnalysis) {
182  pEStructEvent->SetPhiWgt(mWeightFile);
183  //pEStructEvent->SetPhiWgt();
184  pEStructEvent->ShiftPhi(); // This step modifies all Phi values to be w.r.t. the reaction plane
185  }
186 
187  manalysis[ia]->doEvent(pEStructEvent);
188  mEventProcessedCounter++;
189  mEventProcessedPerType[ia]++;
190  if(mQAHists)mQAHists->fillHistograms(pEStructEvent,mreader);
191  mCurrentAnalysis = manalysis[ia];
192  }
193 
194  if (doPrintMemoryInfo) {
195  StMemoryInfo::instance()->snapshot();
196  StMemoryInfo::instance()->print();
197  }
198 
199  return kStOK;
200 }
201 
202 int StEStructAnalysisMaker::getAnalysisIndex(){
203 
204  //if(numAnalysis==1) return 0; // this was a bug, for jobs with 1 analysis centrality limits will be ignored
205 
206 // currently all we index on is centrality,
207 // but this method could be a switch statement
208 // over some flag known to the maker
209 
210  StEStructCentrality* cent=StEStructCentrality::Instance();
211  return cent->centrality( pEStructEvent->Centrality() );
212 }
213 
214 //-----------------------------------------------------------------
215 void StEStructAnalysisMaker::writeQAHists(const char* fileName){
216 
217  TFile * tfq=new TFile(fileName,"RECREATE");
218  if(!tfq){
219  gMessMgr->Warning()<<" QAfile = "<<fileName<<" NOT OPENED!!"<<endm;
220  return;
221  }
222 
223  if(mQAHists)mQAHists->writeHistograms(tfq);
224  for(int i=0;i<numAnalysis;i++)manalysis[i]->writeQAHists(tfq);
225 
226  tfq->Close();
227 }
228 
229 // quickSort
230 //
231 // This public-domain C implementation by Darel Rex Finley.
232 //
233 // * Returns YES if sort was successful, or NO if the nested
234 // pivots went too deep, in which case your array will have
235 // been re-ordered, but probably not sorted correctly.
236 //
237 // * This function assumes it is called with valid parameters.
238 //
239 // * Example calls:
240 // quickSort(&myArray[0],5); // sorts elements 0, 1, 2, 3, and 4
241 // quickSort(&myArray[3],5); // sorts elements 3, 4, 5, 6, and 7
242 
243 bool StEStructAnalysisMaker::quickSort(int *arr, int elements) {
244 
245  #define MAX_LEVELS 1000
246 
247  int piv, beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R, pM ;
248  mIndex = new int[elements];
249  for (int i=0;i<elements;i++) {
250  mIndex[i] = i;
251  }
252 
253  beg[0]=0; end[0]=elements;
254  while (i>=0) {
255  L=beg[i]; R=end[i]-1;
256  if (L<R) {
257  piv=arr[L];
258  pM =mIndex[L];
259  if (i==MAX_LEVELS-1) return false;
260  while (L<R) {
261  while (arr[R]>=piv && L<R) R--;
262  if (L<R) {
263  mIndex[L]=mIndex[R];
264  arr[L++]=arr[R];
265  }
266  while (arr[L]<=piv && L<R) L++;
267  if (L<R) {
268  mIndex[R]=mIndex[L];
269  arr[R--]=arr[L];
270  }
271  }
272  arr[L]=piv;
273  mIndex[L]=pM;
274  beg[i+1]=L+1;
275  end[i+1]=end[i];
276  end[i++]=L;
277  } else {
278  i--;
279  }
280  }
281  return true;
282 }
283 bool StEStructAnalysisMaker::quickSort(double *arr, int elements) {
284 
285  #define MAX_LEVELS 1000
286 
287  double piv;
288  int beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R, pM ;
289  mIndex = new int[elements];
290  for (int i=0;i<elements;i++) {
291  mIndex[i] = i;
292  }
293 
294  beg[0]=0; end[0]=elements;
295  while (i>=0) {
296  L=beg[i]; R=end[i]-1;
297  if (L<R) {
298  piv=arr[L];
299  pM =mIndex[L];
300  if (i==MAX_LEVELS-1) return false;
301  while (L<R) {
302  while (arr[R]>=piv && L<R) R--;
303  if (L<R) {
304  mIndex[L]=mIndex[R];
305  arr[L++]=arr[R];
306  }
307  while (arr[L]<=piv && L<R) L++;
308  if (L<R) {
309  mIndex[R]=mIndex[L];
310  arr[R--]=arr[L];
311  }
312  }
313  arr[L]=piv;
314  mIndex[L]=pM;
315  beg[i+1]=L+1;
316  end[i+1]=end[i];
317  end[i++]=L;
318  } else {
319  i--;
320  }
321  }
322  return true;
323 }
324 int StEStructAnalysisMaker::GetSortedIndex(int i) {
325  return mIndex[i];
326 }
327 
328 //-----------------------------------------------------------------
329 void StEStructAnalysisMaker::writeDiagnostics(int opt){
330 
331  for(int i=0;i<numAnalysis;i++)manalysis[i]->writeDiagnostics();
332 
333 }
334 
335 void StEStructAnalysisMaker::startTimer(){
336  if(!mtimer) mtimer=new StMuTimer;
337  mtimer->start();
338 }
339 
340 void StEStructAnalysisMaker::stopTimer(){ if(mtimer)mtimer->stop(); }
341 
342 void StEStructAnalysisMaker::compiledLoop(){
343  /* no-op here but one could put the event loop of a macro here
344  for some speed increase
345  */
346 }
347 
348 void StEStructAnalysisMaker::SetReactionPlaneAnalysis(char* weightFile) {
349  doReactionPlaneAnalysis = true;
350  mWeightFile = weightFile;
351  cout << " Setting doReactionPlaneAnalysis = " << doReactionPlaneAnalysis << " with a weight file " << mWeightFile << endl;
352 }
353 
354 //-----------------------------------------
355 //-----------------------------------------------------------
356 //-------------------------------------------------------------------------
357 //------------------------------------------------------------------------
358 //-------------------------------------------------------------------------
359 
360 /***********************************************************************
361  *
362  * $Log: StEStructAnalysisMaker.cxx,v $
363  * Revision 1.9 2012/11/16 21:19:05 prindle
364  * Moved EventCuts, TrackCuts to EventReader. Affects most readers.
365  * Added support to write and read EStructEvents.
366  * Cuts: 3D histo support, switch to control filling of histogram for reading EStructEvents
367  * EventCuts: A few new cuts
368  * MuDstReader: Add 2D to some histograms, treat ToFCut, PrimaryCuts, VertexRadius histograms like other cut histograms.
369  * QAHists: Add refMult
370  * TrackCuts: Add some hijing cuts.
371  *
372  * Revision 1.8 2010/03/02 21:43:37 prindle
373  * Use outerHelix() for global tracks
374  * Add sensible triggerId histograms
375  * Starting to add support to sort events (available for Hijing)
376  *
377  * Revision 1.7 2007/01/26 17:09:25 msd
378  * Minor bug fix in AnalysisMaker, cleaned up EmptyAnalysis
379  *
380  * Revision 1.6 2006/05/01 17:49:57 msd
381  * Closed QA tfile
382  *
383  * Revision 1.5 2006/04/26 18:48:57 dkettler
384  *
385  * Added reaction plane determination for the analysis
386  *
387  * Revision 1.4 2006/04/06 00:53:52 prindle
388  * Tried to rationalize the way centrality is defined.
389  * Now the reader gives a float to StEStructEvent and this float is
390  * what is being used to define centrality. When we need a centrality
391  * bin index we pass this number into the centrality singleton object.
392  *
393  * Revision 1.3 2006/04/04 22:05:03 porter
394  * a handful of changes:
395  * - changed the StEStructAnalysisMaker to contain 1 reader not a list of readers
396  * - added StEStructQAHists object to contain histograms that did exist in macros or elsewhere
397  * - made centrality event cut taken from StEStructCentrality singleton
398  * - put in ability to get any max,min val from the cut class - one must call setRange in class
399  *
400  * Revision 1.2 2005/09/07 20:18:35 prindle
401  * AnalysisMaker: Keep track of currentAnalysis (for use in doEStruct macro)
402  * EventCuts.h: Added trigger cuts including cucu and year 4.
403  * MuDstReader: Added dE/dx histograms. Re-arranged code to count tracks
404  * before making centrality cut.
405  * TrackCuts: Random changes. Moved some variables from private to public.o
406  *
407  * Revision 1.1 2003/10/15 18:20:31 porter
408  * initial check in of Estruct Analysis maker codes.
409  *
410  *
411  *********************************************************************/
412 
413 
414 
415 
416 
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
void Clear(Option_t *option="")
User defined functions.
Definition: Stypes.h:43
Definition: Stypes.h:40
Definition: Stypes.h:41