StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtLikeSignAnalysis.cxx
1 /***************************************************************************
2  *
3  * $Id: StHbtLikeSignAnalysis.cxx,v 1.4 2003/09/02 17:58:32 perev Exp $
4  *
5  * Author: Frank Laue, Ohio State, Laue@mps.ohio-state.edu
6  ***************************************************************************
7  *
8  * Description: part of STAR HBT Framework: StHbtMaker package
9  * This is the Class for Analysis objects. Each of the simultaneous
10  * Analyses running should have one of these instantiated. They link
11  * into the Manager in an Analysis Collection.
12  *
13  ***************************************************************************/
14 
15 #include "StHbtMaker/Infrastructure/StHbtLikeSignAnalysis.h"
16 #include "StHbtMaker/Infrastructure/StHbtParticleCollection.hh"
17 #include "StHbtMaker/Base/StHbtTrackCut.h"
18 #include "StHbtMaker/Base/StHbtV0Cut.h"
19 #include "StHbtMaker/Infrastructure/StHbtPicoEventCollectionVector.hh"
20 #include "StHbtMaker/Infrastructure/StHbtPicoEventCollectionVectorHideAway.hh"
21 #include "Stiostream.h"
22 
23 #ifdef __ROOT__
24 ClassImp(StHbtLikeSignAnalysis)
25 #endif
26 
27 // this little function used to apply ParticleCuts (TrackCuts or V0Cuts) and fill ParticleCollections of picoEvent
28 // it is called from StHbtAnalysis::ProcessEvent()
29 
30 
31 extern void FillHbtParticleCollection(StHbtParticleCut* partCut,
32  StHbtEvent* hbtEvent,
33  StHbtParticleCollection* partCollection);
34 
35 
36 //____________________________
37 StHbtLikeSignAnalysis::StHbtLikeSignAnalysis(unsigned int bins, double min, double max) : StHbtAnalysis() {
38  mVertexBins = bins;
39  mVertexZ[0] = min;
40  mVertexZ[1] = max;
41  mUnderFlow = 0;
42  mOverFlow = 0;
43  if (mMixingBuffer) delete mMixingBuffer;
44  mPicoEventCollectionVectorHideAway = new StHbtPicoEventCollectionVectorHideAway(mVertexBins,mVertexZ[0],mVertexZ[1]);
45  /* no-op */
46 }
47 //____________________________
48 StHbtLikeSignAnalysis::StHbtLikeSignAnalysis(const StHbtLikeSignAnalysis& a) : StHbtAnalysis(a) {
49  mVertexBins = a.mVertexBins;
50  mVertexZ[0] = a.mVertexZ[0];
51  mVertexZ[1] = a.mVertexZ[1];
52  mUnderFlow = 0;
53  mOverFlow = 0;
54  if (mMixingBuffer) delete mMixingBuffer;
55  mPicoEventCollectionVectorHideAway = new StHbtPicoEventCollectionVectorHideAway(mVertexBins,mVertexZ[0],mVertexZ[1]);
56  }
57 //____________________________
58 StHbtLikeSignAnalysis::~StHbtLikeSignAnalysis(){
59  delete mPicoEventCollectionVectorHideAway; mPicoEventCollectionVectorHideAway=0;
60 }
61 //____________________________
62 StHbtString StHbtLikeSignAnalysis::Report()
63 {
64  char Ctemp[200];
65  cout << "StHbtLikeSignAnalysis - constructing Report..."<<endl;
66  StHbtString temp = "-----------\nHbt Analysis Report:\n";
67  sprintf(Ctemp,"Events are mixed in %d bins in the range %E cm to %E cm.\n",mVertexBins,mVertexZ[0],mVertexZ[1]);
68  temp += Ctemp;
69  sprintf(Ctemp,"Events underflowing: %d\n",mUnderFlow);
70  temp += Ctemp;
71  sprintf(Ctemp,"Events overflowing: %d\n",mOverFlow);
72  temp += Ctemp;
73  sprintf(Ctemp,"Now adding StHbtAnalysis(base) Report\n");
74  temp += Ctemp;
75  temp += "Adding StHbtAnalysis(base) Report now:\n";
76  temp += StHbtAnalysis::Report();
77  temp += "-------------\n";
78  StHbtString returnThis=temp;
79  return returnThis;
80 }
81 //_________________________
83  // get right mixing buffer
84  double vertexZ = hbtEvent->PrimVertPos().z();
85  mMixingBuffer = mPicoEventCollectionVectorHideAway->PicoEventCollection(vertexZ);
86  if (!mMixingBuffer) {
87  if ( vertexZ < mVertexZ[0] ) mUnderFlow++;
88  if ( vertexZ > mVertexZ[1] ) mOverFlow++;
89  return;
90  }
91 
92  // startup for EbyE
93  EventBegin(hbtEvent);
94  // event cut and event cut monitor
95  bool tmpPassEvent = mEventCut->Pass(hbtEvent);
96  mEventCut->FillCutMonitor(hbtEvent, tmpPassEvent);
97  if (tmpPassEvent) {
98  mNeventsProcessed++;
99  cout << "StHbtLikeSignAnalysis::ProcessEvent() - " << hbtEvent->TrackCollection()->size();
100  cout << " #track=" << hbtEvent->TrackCollection()->size();
101  // OK, analysis likes the event-- build a pico event from it, using tracks the analysis likes...
102  StHbtPicoEvent* picoEvent = new StHbtPicoEvent; // this is what we will make pairs from and put in Mixing Buffer
103  FillHbtParticleCollection(mFirstParticleCut,(StHbtEvent*)hbtEvent,picoEvent->FirstParticleCollection());
104  if ( !(AnalyzeIdenticalParticles()) )
105  FillHbtParticleCollection(mSecondParticleCut,(StHbtEvent*)hbtEvent,picoEvent->SecondParticleCollection());
106  cout <<" #particles in First, Second Collections: " <<
107  picoEvent->FirstParticleCollection()->size() << " " <<
108  picoEvent->SecondParticleCollection()->size() << endl;
109 
110  if (picoEvent->SecondParticleCollection()->size()*picoEvent->FirstParticleCollection()->size()==0) {
111  delete picoEvent;
112  cout << "StHbtLikeSignAnalysis - picoEvent deleted due to empty collection " <<endl;
113  return;
114  }
115  // OK, pico event is built
116  // make real pairs...
117 
118  // Fabrice points out that we do not need to keep creating/deleting pairs all the time
119  // We only ever need ONE pair, and we can just keep changing internal pointers
120  // this should help speed things up
121  StHbtPair* ThePair = new StHbtPair;
122 
123  StHbtParticleIterator PartIter1;
124  StHbtParticleIterator PartIter2;
125  StHbtCorrFctnIterator CorrFctnIter;
126  StHbtParticleIterator StartOuterLoop = picoEvent->FirstParticleCollection()->begin(); // always
127  StHbtParticleIterator EndOuterLoop = picoEvent->FirstParticleCollection()->end(); // will be one less if identical
128  StHbtParticleIterator StartInnerLoop;
129  StHbtParticleIterator EndInnerLoop;
130  if (AnalyzeIdenticalParticles()) { // only use First collection
131  EndOuterLoop--; // outer loop goes to next-to-last particle in First collection
132  EndInnerLoop = picoEvent->FirstParticleCollection()->end() ; // inner loop goes to last particle in First collection
133  }
134  else { // nonidentical - loop over First and Second collections
135  StartInnerLoop = picoEvent->SecondParticleCollection()->begin(); // inner loop starts at first particle in Second collection
136  EndInnerLoop = picoEvent->SecondParticleCollection()->end() ; // inner loop goes to last particle in Second collection
137  }
138  // real pairs
139  for (PartIter1=StartOuterLoop;PartIter1!=EndOuterLoop;PartIter1++){
140  if (AnalyzeIdenticalParticles()){
141  StartInnerLoop = PartIter1;
142  StartInnerLoop++;
143  }
144  ThePair->SetTrack1(*PartIter1);
145  for (PartIter2 = StartInnerLoop; PartIter2!=EndInnerLoop;PartIter2++){
146  ThePair->SetTrack2(*PartIter2);
147  // The following lines have to be uncommented if you want pairCutMonitors
148  // they are not in for speed reasons
149  // bool tmpPassPair = mPairCut->Pass(ThePair);
150  // mPairCut->FillCutMonitor(ThePair, tmpPassPair);
151  // if ( tmpPassPair ) {
152  if (mPairCut->Pass(ThePair)){
153  for (CorrFctnIter=mCorrFctnCollection->begin();
154  CorrFctnIter!=mCorrFctnCollection->end();CorrFctnIter++){
155  StHbtLikeSignCorrFctn* CorrFctn = dynamic_cast<StHbtLikeSignCorrFctn*>(*CorrFctnIter);
156  if (CorrFctn) CorrFctn->AddRealPair(ThePair);
157  }
158  } // if passed pair cut
159  } // loop over second particle
160  } // loop over first particle
161 #ifdef STHBTDEBUG
162  cout << "StHbtLikeSignAnalysis::ProcessEvent() - reals done" << endl;
163 #endif
164 
165  StHbtParticleIterator nextIter;
166  StHbtParticleIterator prevIter;
167 
168  // like sign first partilce collection pairs
169  prevIter = EndOuterLoop;
170  prevIter--;
171  for (PartIter1=StartOuterLoop;PartIter1!=prevIter;PartIter1++){
172  ThePair->SetTrack1(*PartIter1);
173  nextIter = PartIter1;
174  nextIter++;
175  for (PartIter2 = nextIter; PartIter2!=EndOuterLoop;PartIter2++){
176  ThePair->SetTrack2(*PartIter2);
177  // The following lines have to be uncommented if you want pairCutMonitors
178  // they are not in for speed reasons
179  // bool tmpPassPair = mPairCut->Pass(ThePair);
180  // mPairCut->FillCutMonitor(ThePair, tmpPassPair);
181  // if ( tmpPassPair ) {
182  if (mPairCut->Pass(ThePair)){
183  for (CorrFctnIter=mCorrFctnCollection->begin();
184  CorrFctnIter!=mCorrFctnCollection->end();CorrFctnIter++){
185  StHbtLikeSignCorrFctn* CorrFctn = dynamic_cast<StHbtLikeSignCorrFctn*>(*CorrFctnIter);
186  if (CorrFctn) CorrFctn->AddLikeSignPositivePair(ThePair);
187  }
188  } // if passed pair cut
189  } // loop over second particle
190  } // loop over first particle
191 #ifdef STHBTDEBUG
192  cout << "StHbtLikeSignAnalysis::ProcessEvent() - like sign first collection done" << endl;
193 #endif
194  // like sign second partilce collection pairs
195  prevIter = EndInnerLoop;
196  prevIter--;
197  for (PartIter1=StartInnerLoop;PartIter1!=prevIter;PartIter1++){
198  ThePair->SetTrack1(*PartIter1);
199  nextIter = PartIter1;
200  nextIter++;
201  for (PartIter2 = nextIter; PartIter2!=EndInnerLoop;PartIter2++){
202  ThePair->SetTrack2(*PartIter2);
203  // The following lines have to be uncommented if you want pairCutMonitors
204  // they are not in for speed reasons
205  // bool tmpPassPair = mPairCut->Pass(ThePair);
206  // mPairCut->FillCutMonitor(ThePair, tmpPassPair);
207  // if ( tmpPassPair ) {
208  if (mPairCut->Pass(ThePair)){
209  for (CorrFctnIter=mCorrFctnCollection->begin();
210  CorrFctnIter!=mCorrFctnCollection->end();CorrFctnIter++){
211  StHbtLikeSignCorrFctn* CorrFctn = dynamic_cast<StHbtLikeSignCorrFctn*>(*CorrFctnIter);
212  if (CorrFctn) CorrFctn->AddLikeSignNegativePair(ThePair);
213  }
214  } // if passed pair cut
215  } // loop over second particle
216  } // loop over first particle
217 #ifdef STHBTDEBUG
218  cout << "StHbtLikeSignAnalysis::ProcessEvent() - like sign second collection done" << endl;
219 #endif
220 
221  if (MixingBufferFull()){
222 #ifdef STHBTDEBUG
223  cout << "Mixing Buffer is full - lets rock and roll" << endl;
224 #endif
225  }
226  else {
227  cout << "Mixing Buffer not full -gotta wait " << MixingBuffer()->size() << endl;
228  }
229  if (MixingBufferFull()){
230  StartOuterLoop = picoEvent->FirstParticleCollection()->begin();
231  EndOuterLoop = picoEvent->FirstParticleCollection()->end();
232  StHbtPicoEvent* storedEvent;
233  StHbtPicoEventIterator picoEventIter;
234  for (picoEventIter=MixingBuffer()->begin();picoEventIter!=MixingBuffer()->end();picoEventIter++){
235  storedEvent = *picoEventIter;
236  if (AnalyzeIdenticalParticles()){
237  StartInnerLoop = storedEvent->FirstParticleCollection()->begin();
238  EndInnerLoop = storedEvent->FirstParticleCollection()->end();
239  }
240  else{
241  StartInnerLoop = storedEvent->SecondParticleCollection()->begin();
242  EndInnerLoop = storedEvent->SecondParticleCollection()->end();
243  }
244  for (PartIter1=StartOuterLoop;PartIter1!=EndOuterLoop;PartIter1++){
245  ThePair->SetTrack1(*PartIter1);
246  for (PartIter2=StartInnerLoop;PartIter2!=EndInnerLoop;PartIter2++){
247  ThePair->SetTrack2(*PartIter2);
248  // testing... cout << "ThePair defined... going to pair cut... ";
249  if (mPairCut->Pass(ThePair)){
250  // testing... cout << " ThePair passed PairCut... ";
251  for (CorrFctnIter=mCorrFctnCollection->begin();
252  CorrFctnIter!=mCorrFctnCollection->end();CorrFctnIter++){
253  StHbtLikeSignCorrFctn* CorrFctn = dynamic_cast<StHbtLikeSignCorrFctn*>(*CorrFctnIter);
254  if (CorrFctn) {
255  CorrFctn->AddMixedPair(ThePair);
256  //cout << " ThePair has been added to MixedPair method " << endl;
257  }
258  }
259  } // if passed pair cut
260  } // loop over second particle
261  } // loop over first particle
262  } // loop over pico-events stored in Mixing buffer
263  // Now get rid of oldest stored pico-event in buffer.
264  // This means (1) delete the event from memory, (2) "pop" the pointer to it from the MixingBuffer
265  delete MixingBuffer()->back();
266  MixingBuffer()->pop_back();
267  } // if mixing buffer is full
268  delete ThePair;
269  MixingBuffer()->push_front(picoEvent); // store the current pico-event in buffer
270  } // if currentEvent is accepted by currentAnalysis
271  EventEnd(hbtEvent); // cleanup for EbyE
272  // cout << "StHbtLikeSignAnalysis::ProcessEvent() - return to caller ... " << endl;
273 }
274 
275 
276 
virtual void ProcessEvent(const StHbtEvent *)
returns reports of all cuts applied and correlation functions being done