StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtAnalysis.cxx
1 /***************************************************************************
2  * Author: Mike Lisa, Ohio State, lisa@mps.ohio-state.edu
3  ***************************************************************************
4  *
5  * Description: part of STAR HBT Framework: StHbtMaker package
6  * This is the Class for Analysis objects. Each of the simultaneous
7  * Analyses running should have one of these instantiated. They link
8  * into the Manager in an Analysis Collection.
9  *
10  ***************************************************************************
11  *
12  *
13  * Revision 1.23 2002/11/20 00:09:26 renault
14  * fill a new monitor with (hbtEvent,partCollection)
15  *
16  * Revision 1.22 2002/11/03 16:40:31 magestro
17  * Modified ProcessEvent(), added MakePairs() method, and implemented immediate event mixing
18  *
19  * Revision 1.21 2002/06/26 17:27:09 lisa
20  * fixed small bug in StHbtAnalysis associated with the new feature to require ParticleCollections to have some minimum number of particles
21  *
22  * Revision 1.20 2002/06/22 17:53:31 lisa
23  * implemented switch to allow user to require minimum number of particles in First and Second ParticleCollections - default value is zero so if user does not Set this value then behaviour is like before
24  *
25  * Revision 1.19 2001/11/06 20:20:53 laue
26  * Order of event-mixing fixed.
27  *
28  * Revision 1.18 2001/05/25 23:23:59 lisa
29  * Added in StHbtKink stuff
30  *
31  * Revision 1.17 2001/04/05 21:57:45 laue
32  * current pico-event becomes a member of the analysis (mPicoEvent) and gets
33  * an access-function (CurrentPicoEvent)
34  *
35  * Revision 1.15 2000/09/13 18:09:09 laue
36  * Bux fix: Delete track cut only once for identical particle hbt
37  *
38  * Revision 1.14 2000/08/31 22:31:30 laue
39  * StHbtAnalysis: output changed (a little bit less)
40  * StHbtEvent: new version, members for reference mult added
41  * StHbtIOBinary: new IO for new StHbtEvent version
42  * StHbtTypes: TTree typedef to StHbtTTree added
43  * StHbtVertexAnalysis: overflow and underflow added
44  *
45  * Revision 1.13 2000/08/11 16:35:40 rcwells
46  * Added number of events processed to each HBT analysis
47  *
48  * Revision 1.12 2000/07/16 22:23:17 laue
49  * I forgot that we moved memberfunctions out of StHbtBaseAnalysis.
50  * So my previous check-ins didn't compile with the library.
51  * Now they do.
52  *
53  * Revision 1.11 2000/07/16 21:38:22 laue
54  * StHbtCoulomb.cxx StHbtSectoredAnalysis.cxx : updated for standalone version
55  * StHbtV0.cc StHbtV0.hh : some cast to prevent compiling warnings
56  * StHbtParticle.cc StHbtParticle.hh : pointers mTrack,mV0 initialized to 0
57  * StHbtIOBinary.cc : some printouts in #ifdef STHBTDEBUG
58  * StHbtEvent.cc : B-Field set to 0.25Tesla, we have to think about a better
59  * solution
60  *
61  * Revision 1.10 2000/07/06 18:45:51 laue
62  * Copy constructor fixed. It couldn't handle identicle particles.
63  *
64  * Revision 1.9 2000/04/13 20:20:22 laue
65  * Event mixing corrected. Now the first collection of the current event is
66  * mixed with the second collection from the mixing buffer _AND_ vice verse
67  *
68  * Revision 1.8 2000/03/23 23:00:01 laue
69  * StHbtAnalysis copy constructor now uses Clone() function of cuts
70  * StHbtTypes now has StHbtTF1 for fitting purposes
71  *
72  * Revision 1.7 2000/03/17 17:23:05 laue
73  * Roberts new three particle correlations implemented.
74  *
75  * Revision 1.6 2000/03/16 02:07:04 laue
76  * Copy constructor added to StHbtAnalysis (only known cuts, corrfctn).
77  *
78  * StHbtBinaryReader can now derive filename from StIOMaker and read a list
79  * of files.
80  *
81  * StHbtManager now holds a collection of StHbtEventWriters (multiple writes
82  * possible now)
83  *
84  * Revision 1.5 2000/02/13 17:17:12 laue
85  * Calls to the EventBegin() and EventEnd() functions implemented
86  * The actual analysis is moved from StHbtManager to StHbtAnalysis
87  *
88  * Revision 1.4 2000/01/25 17:35:16 laue
89  * I. In order to run the stand alone version of the StHbtMaker the following
90  * changes have been done:
91  * a) all ClassDefs and ClassImps have been put into #ifdef __ROOT__ statements
92  * b) unnecessary includes of StMaker.h have been removed
93  * c) the subdirectory StHbtMaker/doc/Make has been created including everything
94  * needed for the stand alone version
95  *
96  * II. To reduce the amount of compiler warning
97  * a) some variables have been type casted
98  * b) some destructors have been declared as virtual
99  *
100  * Revision 1.3 1999/10/04 15:38:53 lisa
101  * include Franks new accessor methods StHbtAnalysis::CorrFctn and StHbtManager::Analysis as well as McEvent example macro
102  *
103  * Revision 1.2 1999/07/06 22:33:22 lisa
104  * Adjusted all to work in pro and new - dev itself is broken
105  *
106  * Revision 1.1.1.1 1999/06/29 16:02:57 lisa
107  * Installation of StHbtMaker
108  *
109  **************************************************************************/
110 
111 #include "StHbtMaker/Infrastructure/StHbtAnalysis.h"
112 #include "StHbtMaker/Base/StHbtTrackCut.h"
113 #include "StHbtMaker/Base/StHbtV0Cut.h"
114 #include "StHbtMaker/Base/StHbtKinkCut.h"
115 #include <string>
116 
117 
118 #ifdef __ROOT__
119 ClassImp(StHbtAnalysis)
120 #endif
121 
122 StHbtEventCut* copyTheCut(StHbtEventCut*);
123 StHbtParticleCut* copyTheCut(StHbtParticleCut*);
124 StHbtPairCut* copyTheCut(StHbtPairCut*);
125 StHbtCorrFctn* copyTheCorrFctn(StHbtCorrFctn*);
126 
127 // this little function used to apply ParticleCuts (TrackCuts or V0Cuts) and fill ParticleCollections of picoEvent
128 // it is called from StHbtAnalysis::ProcessEvent()
129 void FillHbtParticleCollection(StHbtParticleCut* partCut,
130  StHbtEvent* hbtEvent,
131  StHbtParticleCollection* partCollection)
132 {
133  switch (partCut->Type()) {
134  case hbtTrack: // cut is cutting on Tracks
135  {
136  StHbtTrackCut* pCut = (StHbtTrackCut*) partCut;
137  StHbtTrack* pParticle;
138  StHbtTrackIterator pIter;
139  StHbtTrackIterator startLoop = hbtEvent->TrackCollection()->begin();
140  StHbtTrackIterator endLoop = hbtEvent->TrackCollection()->end();
141  for (pIter=startLoop;pIter!=endLoop;pIter++){
142  pParticle = *pIter;
143  bool tmpPassParticle = pCut->Pass(pParticle);
144  pCut->FillCutMonitor(pParticle, tmpPassParticle);
145  if (tmpPassParticle){
146  StHbtParticle* particle = new StHbtParticle(pParticle,pCut->Mass());
147  partCollection->push_back(particle);
148  }
149  }
150  break;
151  }
152  case hbtV0: // cut is cutting on V0s
153  {
154  StHbtV0Cut* pCut = (StHbtV0Cut*) partCut;
155  StHbtV0* pParticle;
156  StHbtV0Iterator pIter;
157  StHbtV0Iterator startLoop = hbtEvent->V0Collection()->begin();
158  StHbtV0Iterator endLoop = hbtEvent->V0Collection()->end();
159  // this following "for" loop is identical to the one above, but because of scoping, I can's see how to avoid repitition...
160  for (pIter=startLoop;pIter!=endLoop;pIter++){
161  pParticle = *pIter;
162  bool tmpPassV0 = pCut->Pass(pParticle);
163  pCut->FillCutMonitor(pParticle,tmpPassV0);
164  if (tmpPassV0){
165  StHbtParticle* particle = new StHbtParticle(pParticle,partCut->Mass());
166  partCollection->push_back(particle);
167  }
168  }
169  pCut->FillCutMonitor(hbtEvent,partCollection);// Gael 19/06/02
170  break;
171  }
172  case hbtKink: // cut is cutting on Kinks -- mal 25May2001
173  {
174  StHbtKinkCut* pCut = (StHbtKinkCut*) partCut;
175  StHbtKink* pParticle;
176  StHbtKinkIterator pIter;
177  StHbtKinkIterator startLoop = hbtEvent->KinkCollection()->begin();
178  StHbtKinkIterator endLoop = hbtEvent->KinkCollection()->end();
179  // this following "for" loop is identical to the one above, but because of scoping, I can's see how to avoid repitition...
180  for (pIter=startLoop;pIter!=endLoop;pIter++){
181  pParticle = *pIter;
182  bool tmpPass = pCut->Pass(pParticle);
183  pCut->FillCutMonitor(pParticle,tmpPass);
184  if (tmpPass){
185  StHbtParticle* particle = new StHbtParticle(pParticle,partCut->Mass());
186  partCollection->push_back(particle);
187  }
188  }
189  break;
190  }
191  default:
192  cout << "FillHbtParticleCollection function (in StHbtAnalysis.cxx) - undefined Particle Cut type!!! \n";
193  }
194 }
195 //____________________________
196 StHbtAnalysis::StHbtAnalysis(){
197  // mControlSwitch = 0;
198  mEventCut = 0;
199  mFirstParticleCut = 0;
200  mSecondParticleCut = 0;
201  mPairCut = 0;
202  mCorrFctnCollection= 0;
203  mCorrFctnCollection = new StHbtCorrFctnCollection;
204  mMixingBuffer = new StHbtPicoEventCollection;
205  mNeventsProcessed = 0;
206  mPicoEvent=0;
207 
208  mPicoEventCollectionVectorHideAway = 0;
209 
210  mMinSizePartCollection=0; // minimum # particles in ParticleCollection
211 
212 }
213 //____________________________
214 
215 StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) : StHbtBaseAnalysis() {
216  //StHbtAnalysis();
217  mEventCut = 0;
218  mFirstParticleCut = 0;
219  mSecondParticleCut = 0;
220  mPairCut = 0;
221  mCorrFctnCollection= 0;
222  mCorrFctnCollection = new StHbtCorrFctnCollection;
223  mMixingBuffer = new StHbtPicoEventCollection;
224  mNeventsProcessed = 0;
225  mPicoEvent=0;
226 
227  // find the right event cut
228  mEventCut = a.mEventCut->Clone();
229  // find the right first particle cut
230  mFirstParticleCut = a.mFirstParticleCut->Clone();
231  // find the right second particle cut
232  if (a.mFirstParticleCut==a.mSecondParticleCut)
233  SetSecondParticleCut(mFirstParticleCut); // identical particle hbt
234  else
235  mSecondParticleCut = a.mSecondParticleCut->Clone();
236 
237  mPairCut = a.mPairCut->Clone();
238 
239  if ( mEventCut ) {
240  SetEventCut(mEventCut); // this will set the myAnalysis pointer inside the cut
241  cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - event cut set " << endl;
242  }
243  if ( mFirstParticleCut ) {
244  SetFirstParticleCut(mFirstParticleCut); // this will set the myAnalysis pointer inside the cut
245  cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - first particle cut set " << endl;
246  }
247  if ( mSecondParticleCut ) {
248  SetSecondParticleCut(mSecondParticleCut); // this will set the myAnalysis pointer inside the cut
249  cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - second particle cut set " << endl;
250  } if ( mPairCut ) {
251  SetPairCut(mPairCut); // this will set the myAnalysis pointer inside the cut
252  cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - pair cut set " << endl;
253  }
254 
255  StHbtCorrFctnIterator iter;
256  for (iter=a.mCorrFctnCollection->begin(); iter!=a.mCorrFctnCollection->end();iter++){
257  cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - looking for correlation functions " << endl;
258  StHbtCorrFctn* fctn = (*iter)->Clone();
259  if (fctn) AddCorrFctn(fctn);
260  else cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - correlation function not found " << endl;
261  }
262 
263  mNumEventsToMix = a.mNumEventsToMix;
264 
265  mMinSizePartCollection = a.mMinSizePartCollection; // minimum # particles in ParticleCollection
266 
267  cout << " StHbtAnalysis::StHbtAnalysis(const StHbtAnalysis& a) - analysis copied " << endl;
268 
269 }
270 //____________________________
271 StHbtAnalysis::~StHbtAnalysis(){
272  cout << " StHbtAnalysis::~StHbtAnalysis()" << endl;
273  if (mEventCut) delete mEventCut; mEventCut=0;
274  if (mFirstParticleCut == mSecondParticleCut) mSecondParticleCut=0;
275  if (mFirstParticleCut) delete mFirstParticleCut; mFirstParticleCut=0;
276  if (mSecondParticleCut) delete mSecondParticleCut; mSecondParticleCut=0;
277  if (mPairCut) delete mPairCut; mPairCut=0;
278  // now delete every CorrFunction in the Collection, and then the Collection itself
279  StHbtCorrFctnIterator iter;
280  for (iter=mCorrFctnCollection->begin(); iter!=mCorrFctnCollection->end();iter++){
281  delete *iter;
282  }
283  delete mCorrFctnCollection;
284  // now delete every PicoEvent in the EventMixingBuffer and then the Buffer itself
285  if (mMixingBuffer) {
286  StHbtPicoEventIterator piter;
287  for (piter=mMixingBuffer->begin();piter!=mMixingBuffer->end();piter++){
288  delete *piter;
289  }
290  delete mMixingBuffer;
291  }
292 }
293 //______________________
294 StHbtCorrFctn* StHbtAnalysis::CorrFctn(int n){ // return pointer to n-th correlation function
295  if ( n<0 || n > (int)mCorrFctnCollection->size() )
296  return NULL;
297  StHbtCorrFctnIterator iter=mCorrFctnCollection->begin();
298  for (int i=0; i<n ;i++){
299  iter++;
300  }
301  return *iter;
302 }
303 //____________________________
304 StHbtString StHbtAnalysis::Report()
305 {
306  cout << "StHbtAnalysis - constructing Report..."<<endl;
307  string temp = "-----------\nHbt Analysis Report:\n";
308  temp += "\nEvent Cuts:\n";
309  temp += mEventCut->Report();
310  temp += "\nParticle Cuts - First Particle:\n";
311  temp += mFirstParticleCut->Report();
312  temp += "\nParticle Cuts - Second Particle:\n";
313  temp += mSecondParticleCut->Report();
314  temp += "\nPair Cuts:\n";
315  temp += mPairCut->Report();
316  temp += "\nCorrelation Functions:\n";
317  StHbtCorrFctnIterator iter;
318  if ( mCorrFctnCollection->size()==0 ) {
319  cout << "StHbtAnalysis-Warning : no correlations functions in this analysis " << endl;
320  }
321  for (iter=mCorrFctnCollection->begin(); iter!=mCorrFctnCollection->end();iter++){
322  temp += (*iter)->Report();
323  temp += "\n";
324  }
325  temp += "-------------\n";
326  StHbtString returnThis=temp;
327  return returnThis;
328 }
329 //_________________________
331  // Add event to processed events
332  mPicoEvent=0; // we will get a new pico event, if not prevent corr. fctn to access old pico event
333  AddEventProcessed();
334  // startup for EbyE
335  EventBegin(hbtEvent);
336  // event cut and event cut monitor
337  bool tmpPassEvent = mEventCut->Pass(hbtEvent);
338  mEventCut->FillCutMonitor(hbtEvent, tmpPassEvent);
339  if (tmpPassEvent) {
340  cout << "StHbtAnalysis::ProcessEvent() - Event has passed cut - build picoEvent from " <<
341  hbtEvent->TrackCollection()->size() << " tracks in TrackCollection" << endl;
342  // OK, analysis likes the event-- build a pico event from it, using tracks the analysis likes...
343  mPicoEvent = new StHbtPicoEvent; // this is what we will make pairs from and put in Mixing Buffer
344  // no memory leak. we will delete picoevents when they come out of the mixing buffer
345  FillHbtParticleCollection(mFirstParticleCut,(StHbtEvent*)hbtEvent,mPicoEvent->FirstParticleCollection());
346  if ( !(AnalyzeIdenticalParticles()) )
347  FillHbtParticleCollection(mSecondParticleCut,(StHbtEvent*)hbtEvent,mPicoEvent->SecondParticleCollection());
348  cout <<"StHbtAnalysis::ProcessEvent - #particles in First, Second Collections: " <<
349  mPicoEvent->FirstParticleCollection()->size() << " " <<
350  mPicoEvent->SecondParticleCollection()->size() << endl;
351 
352  // mal - implement a switch which allows only using events with ParticleCollections containing a minimum
353  // number of entries (jun2002)
354  if ((mPicoEvent->FirstParticleCollection()->size() >= mMinSizePartCollection )
355  && ( AnalyzeIdenticalParticles() || (mPicoEvent->SecondParticleCollection()->size() >= mMinSizePartCollection ))) {
356 
357 
358 //------------------------------------------------------------------------------
359 // Temporary comment:
360 // This whole section rewritten so that all pairs are built using the
361 // same code... easier to read and manage, and MakePairs() can be called by
362 // derived classes. Also, the requirement of a full mixing buffer before
363 // mixing is removed.
364 // Dan Magestro, 11/2002
365 
366  //------ Make real pairs. If identical, make pairs for one collection ------//
367 
368  if (AnalyzeIdenticalParticles()) {
369  MakePairs("real", mPicoEvent->FirstParticleCollection() );
370  }
371  else {
372  MakePairs("real", mPicoEvent->FirstParticleCollection(),
373  mPicoEvent->SecondParticleCollection() );
374  }
375  cout << "StHbtAnalysis::ProcessEvent() - reals done ";
376 
377  //---- Make pairs for mixed events, looping over events in mixingBuffer ----//
378 
379  StHbtPicoEvent* storedEvent;
380  StHbtPicoEventIterator mPicoEventIter;
381 
382  for (mPicoEventIter=MixingBuffer()->begin();mPicoEventIter!=MixingBuffer()->end();mPicoEventIter++){
383  storedEvent = *mPicoEventIter;
384 
385  if (AnalyzeIdenticalParticles()) {
386  MakePairs("mixed",mPicoEvent->FirstParticleCollection(),
387  storedEvent->FirstParticleCollection() );
388  }
389  else {
390  MakePairs("mixed",mPicoEvent->FirstParticleCollection(),
391  storedEvent->SecondParticleCollection() );
392 
393  MakePairs("mixed",storedEvent->FirstParticleCollection(),
394  mPicoEvent->SecondParticleCollection() );
395  }
396  }
397  cout << " - mixed done " << endl;
398 
399  //--------- If mixing buffer is full, delete oldest event ---------//
400 
401  if ( MixingBufferFull() ) {
402  delete MixingBuffer()->back();
403  MixingBuffer()->pop_back();
404  }
405 
406  //-------- Add current event (mPicoEvent) to mixing buffer --------//
407 
408  MixingBuffer()->push_front(mPicoEvent);
409 
410 
411 // Temporary comment: End of rewritten section... Dan Magestro, 11/2002
412 //------------------------------------------------------------------------------
413 
414 
415  } // if ParticleCollections are big enough (mal jun2002)
416  else{
417  delete mPicoEvent;
418  }
419  } // if currentEvent is accepted by currentAnalysis
420  EventEnd(hbtEvent); // cleanup for EbyE
421  //cout << "StHbtAnalysis::ProcessEvent() - return to caller ... " << endl;
422 }
423 //_________________________
424 void StHbtAnalysis::MakePairs(const char* typeIn, StHbtParticleCollection *partCollection1,
425  StHbtParticleCollection *partCollection2){
426 // Build pairs, check pair cuts, and call CFs' AddRealPair() or
427 // AddMixedPair() methods. If no second particle collection is
428 // specfied, make pairs within first particle collection.
429 
430  string type = typeIn;
431 
432  StHbtPair* ThePair = new StHbtPair;
433 
434  StHbtCorrFctnIterator CorrFctnIter;
435 
436  StHbtParticleIterator PartIter1, PartIter2;
437 
438  StHbtParticleIterator StartOuterLoop = partCollection1->begin(); // always
439  StHbtParticleIterator EndOuterLoop = partCollection1->end(); // will be one less if identical
440  StHbtParticleIterator StartInnerLoop;
441  StHbtParticleIterator EndInnerLoop;
442 
443  if (partCollection2) { // Two collections:
444  StartInnerLoop = partCollection2->begin(); // Full inner & outer loops
445  EndInnerLoop = partCollection2->end(); //
446  }
447  else { // One collection:
448  EndOuterLoop--; // Outer loop goes to next-to-last particle
449  EndInnerLoop = partCollection1->end() ; // Inner loop goes to last particle
450  }
451 
452  for (PartIter1=StartOuterLoop;PartIter1!=EndOuterLoop;PartIter1++) {
453  if (!partCollection2){
454  StartInnerLoop = PartIter1;
455  StartInnerLoop++;
456  }
457  ThePair->SetTrack1(*PartIter1);
458 
459  for (PartIter2 = StartInnerLoop; PartIter2!=EndInnerLoop;PartIter2++) {
460 
461  ThePair->SetTrack2(*PartIter2);
462 
463  // The following lines have to be uncommented if you want pairCutMonitors
464  // they are not in for speed reasons
465  // bool tmpPassPair = mPairCut->Pass(ThePair);
466  // mPairCut->FillCutMonitor(ThePair, tmpPassPair);
467  // if ( tmpPassPair )
468 
469  //---- If pair passes cut, loop over CF's and add pair to real/mixed ----//
470 
471  if (mPairCut->Pass(ThePair)){
472  for (CorrFctnIter=mCorrFctnCollection->begin();
473  CorrFctnIter!=mCorrFctnCollection->end();CorrFctnIter++){
474  StHbtCorrFctn* CorrFctn = *CorrFctnIter;
475 
476  if(type == "real")
477  CorrFctn->AddRealPair(ThePair);
478  else if(type == "mixed")
479  CorrFctn->AddMixedPair(ThePair);
480  else
481  cout << "Problem with pair type, type = " << type.c_str() << endl;
482 
483  }
484  }
485 
486  } // loop over second particle
487  } // loop over first particle
488 
489  delete ThePair;
490 
491 }
492 //_________________________
493 void StHbtAnalysis::EventBegin(const StHbtEvent* ev){
494  //cout << " StHbtAnalysis::EventBegin(const StHbtEvent* ev) " << endl;
495  mFirstParticleCut->EventBegin(ev);
496  mSecondParticleCut->EventBegin(ev);
497  mPairCut->EventBegin(ev);
498  for (StHbtCorrFctnIterator iter=mCorrFctnCollection->begin(); iter!=mCorrFctnCollection->end();iter++){
499  (*iter)->EventBegin(ev);
500  }
501 }
502 //_________________________
503 void StHbtAnalysis::EventEnd(const StHbtEvent* ev){
504  mFirstParticleCut->EventEnd(ev);
505  mSecondParticleCut->EventEnd(ev);
506  mPairCut->EventEnd(ev);
507  for (StHbtCorrFctnIterator iter=mCorrFctnCollection->begin(); iter!=mCorrFctnCollection->end();iter++){
508  (*iter)->EventEnd(ev);
509  }
510 }
511 //_________________________
512 void StHbtAnalysis::Finish(){
513  StHbtCorrFctnIterator iter;
514  for (iter=mCorrFctnCollection->begin(); iter!=mCorrFctnCollection->end();iter++){
515  (*iter)->Finish();
516  }
517 }
518 //_________________________
519 void StHbtAnalysis::AddEventProcessed() {
520  mNeventsProcessed++;
521 }
virtual void ProcessEvent(const StHbtEvent *)
returns reports of all cuts applied and correlation functions being done