2 #include "AliHBTAnalysis.h"
7 #include "AliHBTReader.h"
8 #include "AliHBTParticle.h"
9 #include "AliHBTParticleCut.h"
10 #include "AliHBTPair.h"
11 #include "AliHBTPairCut.h"
12 #include "AliHBTFunction.h"
18 ClassImp(AliHBTAnalysis)
20 const UInt_t AliHBTAnalysis::fgkFctnArraySize = 100;
21 const Int_t AliHBTAnalysis::fgkHbtAnalyzeAll = 0;
23 AliHBTAnalysis::AliHBTAnalysis()
27 fTrackFunctions = new AliHBTOnePairFctn* [fgkFctnArraySize];
28 fParticleFunctions = new AliHBTOnePairFctn* [fgkFctnArraySize];
29 fParticleAndTrackFunctions = new AliHBTTwoPairFctn* [fgkFctnArraySize];
32 fNParticleFunctions = 0;
33 fNParticleAndTrackFunctions = 0;
35 fPairCut = new AliHBTEmptyPairCut();//empty cut - accepts all particles
39 /*************************************************************************************/
41 AliHBTAnalysis::~AliHBTAnalysis()
44 //note that we do not delete functions itself
45 // they should be deleted by whom where created
46 //we only store pointers, and we use "new" only for pointers array
47 delete [] fTrackFunctions;
48 delete [] fParticleFunctions;
49 delete [] fParticleAndTrackFunctions;
51 delete fPairCut; // always have an copy of an object - we create we dstroy
54 /*************************************************************************************/
56 void AliHBTAnalysis::Process(Option_t* option)
58 //default option = "TracksAndParticles"
59 //Main method of the HBT Analysis Package
60 //It triggers reading with the global cut (default is an empty cut)
61 //Than it checks options and data which are read
62 //if everything is OK, then it calls one of the looping methods
63 //depending on tfReaderhe option
64 //These methods differs on what thay are looping on
67 //--------------------------------------------------------------------
68 //ProcessTracksAndParticles - "TracksAndParticles"
70 // it loops over both, tracks(reconstructed) and particles(simulated)
71 // all function gethered in all 3 lists are called for each (double)pair
73 //ProcessTracks - "Tracks"
74 // it loops only on tracks(reconstructed),
75 // functions ONLY from fTrackFunctions list are called
77 //ProcessParticles - "Particles"
78 // it loops only on particles(simulated),
79 // functions ONLY from fParticleAndTrackFunctions list are called
84 Error("Process","The reader is not set");
89 const char *oT = strstr(option,"Tracks");
90 const char *oP = strstr(option,"Particles");
94 if (fReader->GetNumberOfPartEvents() <1)
96 Error("Process","There is no Particles. Maybe change the option?");
99 if (fReader->GetNumberOfTrackEvents() <1)
101 Error("Process","There is no Tracks. Maybe change the option?");
105 if ( RunCoherencyCheck() )
108 "Coherency check not passed. Maybe change the option?\n");
111 ProcessTracksAndParticles();
117 if (fReader->GetNumberOfTrackEvents() <1)
119 Error("Process","There is no data to analyze.");
128 if (fReader->GetNumberOfPartEvents() <1)
130 Error("Process","There is no data to analyze.");
139 /*************************************************************************************/
141 void AliHBTAnalysis::ProcessTracksAndParticles()
144 //In order to minimize calling AliRun::GetEvent (we need at one time particles from different events),
145 //the loops are splited
148 AliHBTParticle * part1, * part2;
149 AliHBTParticle * track1, * track2;
151 AliHBTEvent * trackEvent, *partEvent;
152 AliHBTEvent * trackEvent2,*partEvent2;
154 // Int_t N1, N2, N=0; //number of particles in current event(we prcess two events in one time)
156 Int_t Nev = fReader->GetNumberOfTrackEvents();
158 /***************************************/
159 /****** Looping same events ********/
160 /****** filling numerators ********/
161 /***************************************/
162 AliHBTPair * trackpair = new AliHBTPair();
163 AliHBTPair * partpair = new AliHBTPair();
165 AliHBTPair * tmptrackpair;//temprary pointers to pairs
166 AliHBTPair * tmppartpair;
170 for (Int_t i = 0;i<Nev;i++)
172 partEvent= fReader->GetParticleEvent(i);
173 trackEvent = fReader->GetTrackEvent(i);
175 if (!partEvent) continue;
179 for (Int_t j = 0; j<partEvent->GetNumberOfParticles() ; j++)
181 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<i<<endl;
183 part1= partEvent->GetParticle(j);
184 track1= trackEvent->GetParticle(j);
186 for (Int_t k =j+1; k < partEvent->GetNumberOfParticles() ; k++)
188 part2= partEvent->GetParticle(k);
189 partpair->SetParticles(part1,part2);
191 track2= trackEvent->GetParticle(k);
192 trackpair->SetParticles(track1,track2);
194 if(fPairCut->Pass(partpair) || (fPairCut->Pass(trackpair))) //check pair cut
195 { //do not meets crietria of the pair cut, try with swaped pairs
196 if( ( fPairCut->Pass(partpair->GetSwapedPair()) ) || ( fPairCut->Pass(trackpair->GetSwapedPair()) ) )
197 continue; //swaped pairs do not meet criteria of pair cut as well, take next particle
199 { //swaped pair meets all the criteria
200 tmppartpair = partpair->GetSwapedPair();
201 tmptrackpair = trackpair->GetSwapedPair();
206 {//meets criteria of the pair cut
207 tmptrackpair = trackpair;
208 tmppartpair = partpair;
211 for(ii = 0;ii<fNParticleFunctions;ii++)
212 fParticleFunctions[ii]->ProcessSameEventParticles(tmppartpair);
214 for(ii = 0;ii<fNTrackFunctions;ii++)
215 fTrackFunctions[ii]->ProcessSameEventParticles(tmptrackpair);
217 for(ii = 0;ii<fNParticleAndTrackFunctions;ii++)
218 fParticleAndTrackFunctions[ii]->ProcessSameEventParticles(tmptrackpair,tmppartpair);
223 /***************************************/
224 /***** Filling denominators *********/
225 /***************************************/
226 for (Int_t i = 0;i<Nev-1;i++) //In each event (but last) ....
229 partEvent= fReader->GetParticleEvent(i);
230 if (!partEvent) continue;
232 trackEvent = fReader->GetTrackEvent(i);
236 for (Int_t j = 0; j< partEvent->GetNumberOfParticles(); j++) // ... Loop over all particles ...
239 part1= partEvent->GetParticle(j);
241 track1= trackEvent->GetParticle(j);
245 if ( ((i+fBufferSize) >= Nev) ||( fBufferSize < 0) ) //if buffer size is negative
246 //or current event+buffersize is greater
247 //than max nuber of events
249 NNN = Nev; //set the max event number
253 NNN = i+fBufferSize; //set the current event number + fBufferSize
256 for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
259 partEvent2= fReader->GetParticleEvent(k);
260 if (!partEvent2) continue;
262 trackEvent2 = fReader->GetTrackEvent(k);
264 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<k<<endl;
266 for(Int_t l = 0; l<partEvent2->GetNumberOfParticles();l++) // ... on all particles
269 // if (N>MAXCOMB) break;
271 part2= partEvent2->GetParticle(l);
272 partpair->SetParticles(part1,part2);
274 track2= trackEvent2->GetParticle(l);
275 trackpair->SetParticles(track1,track2);
277 if( (fPairCut->Pass(partpair)) || (fPairCut->Pass(trackpair)) ) //check pair cut
278 { //do not meets crietria of the
279 if( ( fPairCut->Pass(partpair->GetSwapedPair()) ) || ( fPairCut->Pass(trackpair->GetSwapedPair()) ) )
283 tmppartpair = partpair->GetSwapedPair();
284 tmptrackpair = trackpair->GetSwapedPair();
288 {//meets criteria of the pair cut
289 tmptrackpair = trackpair;
290 tmppartpair = partpair;
293 for(ii = 0;ii<fNParticleFunctions;ii++)
294 fParticleFunctions[ii]->ProcessDiffEventParticles(tmppartpair);
296 for(ii = 0;ii<fNTrackFunctions;ii++)
297 fTrackFunctions[ii]->ProcessDiffEventParticles(tmptrackpair);
299 for(ii = 0;ii<fNParticleAndTrackFunctions;ii++)
300 fParticleAndTrackFunctions[ii]->ProcessDiffEventParticles(tmptrackpair,tmppartpair);
303 }//for(Int_t l = 0; l<N2;l++) // ... on all particles
304 }//for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
309 /***************************************/
313 /*************************************************************************************/
315 void AliHBTAnalysis::ProcessTracks()
317 //In order to minimize calling AliRun::GetEvent (we need at one time particles from different events),
318 //the loops are splited
319 AliHBTParticle * track1, * track2;
321 AliHBTEvent * trackEvent;
322 AliHBTEvent * trackEvent2;
324 // Int_t N1, N2, N=0; //number of particles in current event(we prcess two events in one time)
326 Int_t Nev = fReader->GetNumberOfTrackEvents();
328 /***************************************/
329 /****** Looping same events ********/
330 /****** filling numerators ********/
331 /***************************************/
332 AliHBTPair * trackpair = new AliHBTPair();
333 AliHBTPair * tmptrackpair; //temporary pointer
335 for (Int_t i = 0;i<Nev;i++)
337 trackEvent = fReader->GetTrackEvent(i);
338 if (!trackEvent) continue;
341 for (Int_t j = 0; j<trackEvent->GetNumberOfParticles() ; j++)
343 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<i<<endl;
345 track1= trackEvent->GetParticle(j);
347 for (Int_t k =j+1; k < trackEvent->GetNumberOfParticles() ; k++)
349 track2= trackEvent->GetParticle(k);
350 trackpair->SetParticles(track1,track2);
351 if(fPairCut->Pass(trackpair)) //check pair cut
352 { //do not meets crietria of the
353 if( fPairCut->Pass(trackpair->GetSwapedPair()) ) continue;
354 else tmptrackpair = trackpair->GetSwapedPair();
358 tmptrackpair = trackpair;
362 for(ii = 0;ii<fNTrackFunctions;ii++)
363 fTrackFunctions[ii]->ProcessSameEventParticles(tmptrackpair);
370 /***************************************/
371 /***** Filling diff histogram *********/
372 /***************************************/
373 for (Int_t i = 0;i<Nev-1;i++) //In each event (but last) ....
375 trackEvent = fReader->GetTrackEvent(i);
376 if (!trackEvent) continue;
379 for (Int_t j = 0; j< trackEvent->GetNumberOfParticles(); j++) // ... Loop over all particles ...
381 // if (N>MAXCOMB) break;
383 track1= trackEvent->GetParticle(j);
387 if ( ((i+fBufferSize) >= Nev) ||( fBufferSize < 0) ) //if buffer size is negative
388 //or current event+buffersize is greater
389 //than max nuber of events
391 NNN = Nev; //set the max event number
395 NNN = i+fBufferSize; //set the current event number + fBufferSize
398 for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
401 trackEvent2 = fReader->GetTrackEvent(k);
402 if (!trackEvent2) continue;
404 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<k<<endl;
406 for(Int_t l = 0; l<trackEvent2->GetNumberOfParticles();l++) // ... on all particles
409 // if (N>MAXCOMB) break;
410 track2= trackEvent2->GetParticle(l);
411 trackpair->SetParticles(track1,track2);
413 if(fPairCut->Pass(trackpair)) //check pair cut
414 { //do not meets crietria of the
415 if( fPairCut->Pass(trackpair->GetSwapedPair()) ) continue;
416 else tmptrackpair = trackpair->GetSwapedPair();
420 tmptrackpair = trackpair;
423 for(ii = 0;ii<fNTrackFunctions;ii++)
424 fTrackFunctions[ii]->ProcessDiffEventParticles(tmptrackpair);
426 }//for(Int_t l = 0; l<N2;l++) // ... on all particles
427 }//for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
432 /***************************************/
437 /*************************************************************************************/
439 void AliHBTAnalysis::ProcessParticles()
441 //In order to minimize calling AliRun::GetEvent (we need at one time particles from different events),
442 //the loops are splited
443 AliHBTParticle * part1, * part2;
445 AliHBTEvent * partEvent;
446 AliHBTEvent * partEvent2;
448 AliHBTPair * partpair = new AliHBTPair();
449 AliHBTPair * tmppartpair; //temporary pointer to the pair
451 // Int_t N1, N2, N=0; //number of particles in current event(we prcess two events in one time)
453 Int_t Nev = fReader->GetNumberOfPartEvents();
456 /***************************************/
457 /****** Looping same events ********/
458 /****** filling numerators ********/
459 /***************************************/
461 for (Int_t i = 0;i<Nev;i++)
463 partEvent= fReader->GetParticleEvent(i);
464 if (!partEvent) continue;
467 for (Int_t j = 0; j<partEvent->GetNumberOfParticles() ; j++)
469 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<i<<endl;
471 part1= partEvent->GetParticle(j);
473 for (Int_t k =j+1; k < partEvent->GetNumberOfParticles() ; k++)
475 part2= partEvent->GetParticle(k);
476 partpair->SetParticles(part1,part2);
478 if( fPairCut->Pass(partpair) ) //check pair cut
479 { //do not meets crietria of the pair cut, try with swaped pairs
480 if( fPairCut->Pass(partpair->GetSwapedPair() ) )
481 continue; //swaped pairs do not meet criteria of pair cut as well, take next particle
483 { //swaped pair meets all the criteria
484 tmppartpair = partpair->GetSwapedPair();
489 tmppartpair = partpair;
494 for(ii = 0;ii<fNParticleFunctions;ii++)
495 fParticleFunctions[ii]->ProcessSameEventParticles(tmppartpair);
500 /***************************************/
501 /***** Filling diff histogram *********/
502 /***************************************/
503 for (Int_t i = 0;i<Nev-1;i++) //In each event (but last)....
505 partEvent= fReader->GetParticleEvent(i);
506 if (!partEvent) continue;
510 for (Int_t j = 0; j< partEvent->GetNumberOfParticles(); j++) // ... Loop over all particles ...
512 // if (N>MAXCOMB) break;
514 part1= partEvent->GetParticle(j);
518 if ( ((i+fBufferSize) >= Nev) ||( fBufferSize < 0) ) //if buffer size is negative
519 //or current event+buffersize is greater
520 //than max nuber of events
522 NNN = Nev; //set the max event number
526 NNN = i+fBufferSize; //set the current event number + fBufferSize
529 // cout<<"NNN = "<<NNN<<endl;
530 for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
533 partEvent2= fReader->GetParticleEvent(k);
534 if (!partEvent2) continue;
536 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<k<<endl;
538 for(Int_t l = 0; l<partEvent2->GetNumberOfParticles();l++) // ... on all particles
541 // if (N>MAXCOMB) break;
542 part2= partEvent2->GetParticle(l);
543 partpair->SetParticles(part1,part2);
545 if(fPairCut->Pass(partpair)) //check pair cut
546 { //do not meets crietria of the
547 if( fPairCut->Pass(partpair->GetSwapedPair()) ) continue;
548 else tmppartpair = partpair->GetSwapedPair();
552 tmppartpair = partpair;
555 for(ii = 0;ii<fNParticleFunctions;ii++)
556 fParticleFunctions[ii]->ProcessDiffEventParticles(tmppartpair);
558 }//for(Int_t l = 0; l<N2;l++) // ... on all particles
559 }//for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
564 /***************************************/
569 /*************************************************************************************/
572 void AliHBTAnalysis::WriteFunctions()
575 for(ii = 0;ii<fNParticleFunctions;ii++)
576 fParticleFunctions[ii]->Write();
578 for(ii = 0;ii<fNTrackFunctions;ii++)
579 fTrackFunctions[ii]->Write();
581 for(ii = 0;ii<fNParticleAndTrackFunctions;ii++)
582 fParticleAndTrackFunctions[ii]->Write();
584 /*************************************************************************************/
586 void AliHBTAnalysis::SetGlobalPairCut(AliHBTPairCut* cut)
590 Error("AliHBTAnalysis::SetGlobalPairCut","Pointer is NULL. Ignoring");
593 fPairCut = (AliHBTPairCut*)cut->Clone();
596 /*************************************************************************************/
598 void AliHBTAnalysis::AddTrackFunction(AliHBTOnePairFctn* f)
600 if (f == 0x0) return;
601 if (fNTrackFunctions == fgkFctnArraySize)
603 Error("AliHBTAnalysis::AddTrackFunction","Can not add this function, not enough place in the array.");
605 fTrackFunctions[fNTrackFunctions] = f;
608 /*************************************************************************************/
610 void AliHBTAnalysis::AddParticleFunction(AliHBTOnePairFctn* f)
612 if (f == 0x0) return;
614 if (fNParticleFunctions == fgkFctnArraySize)
616 Error("AliHBTAnalysis::AddParticleFunction","Can not add this function, not enough place in the array.");
618 fParticleFunctions[fNParticleFunctions] = f;
619 fNParticleFunctions++;
623 void AliHBTAnalysis::AddParticleAndTrackFunction(AliHBTTwoPairFctn* f)
625 if (f == 0x0) return;
626 if (fNParticleAndTrackFunctions == fgkFctnArraySize)
628 Error("AliHBTAnalysis::AddParticleAndTrackFunction","Can not add this function, not enough place in the array.");
630 fParticleAndTrackFunctions[fNParticleAndTrackFunctions] = f;
631 fNParticleAndTrackFunctions++;
635 /*************************************************************************************/
638 /*************************************************************************************/
640 Bool_t AliHBTAnalysis::RunCoherencyCheck()
642 //Checks if both HBTRuns are similar
643 //return true if error found
644 //if they seem to be OK return false
646 cout<<"Checking HBT Runs Coherency"<<endl;
648 cout<<"Number of events ..."; fflush(stdout);
650 if (fReader->GetNumberOfPartEvents() == fReader->GetNumberOfTrackEvents() ) //check whether there is the same number of events
652 cout<<"OK. "<<fReader->GetNumberOfTrackEvents()<<" found"<<endl;
655 { //if not the same - ERROR
656 Error("AliHBTAnalysis::RunCoherencyCheck()",
657 "Number of simulated events (%d) is not equal to number of reconstructed events(%d)",
658 fReader->GetNumberOfPartEvents(),fReader->GetNumberOfTrackEvents());
662 cout<<"Checking number of Particles AND Particles Types in each event ...";fflush(stdout);
664 AliHBTEvent *partEvent;
665 AliHBTEvent *trackEvent;
666 for( i = 0; i<fReader->GetNumberOfTrackEvents();i++)
668 partEvent= fReader->GetParticleEvent(i); //gets the "ith" event
669 trackEvent = fReader->GetTrackEvent(i);
671 if ( (partEvent == 0x0) && (partEvent == 0x0) ) continue;
672 if ( (partEvent == 0x0) || (partEvent == 0x0) )
674 Error("AliHBTAnalysis::RunCoherencyCheck()",
675 "One event is NULL and the other one not. Event Number %d",i);
679 if ( partEvent->GetNumberOfParticles() != trackEvent->GetNumberOfParticles() )
681 Error("AliHBTAnalysis::RunCoherencyCheck()",
682 "Event %d: Number of simulated particles (%d) not equal to number of reconstructed tracks (%d)",
683 i,partEvent->GetNumberOfParticles() , trackEvent->GetNumberOfParticles());
687 for (Int_t j = 0; j<partEvent->GetNumberOfParticles(); j++)
689 if( partEvent->GetParticle(j)->GetPdgCode() != trackEvent->GetParticle(j)->GetPdgCode() )
691 Error("AliHBTAnalysis::RunCoherencyCheck()",
692 "Event %d: Particle %d: PID of simulated particle (%d) not the same of reconstructed track (%d)",
693 i,j, partEvent->GetParticle(j)->GetPdgCode(),trackEvent->GetParticle(j)->GetPdgCode() );
700 cout<<" Everything looks OK"<<endl;
705 /*************************************************************************************/
708 /*************************************************************************************/