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
38 /*************************************************************************************/
40 AliHBTAnalysis::~AliHBTAnalysis()
43 //note that we do not delete functions itself
44 // they should be deleted by whom where created
45 //we only store pointers, and we use "new" only for pointers array
46 delete [] fTrackFunctions;
47 delete [] fParticleFunctions;
48 delete [] fParticleAndTrackFunctions;
50 delete fPairCut; // always have an copy of an object - we create we dstroy
53 /*************************************************************************************/
55 void AliHBTAnalysis::Process(Option_t* option)
57 //default option = "TracksAndParticles"
58 //Main method of the HBT Analysis Package
59 //It triggers reading with the global cut (default is an empty cut)
60 //Than it checks options and data which are read
61 //if everything is OK, then it calls one of the looping methods
62 //depending on tfReaderhe option
63 //These methods differs on what thay are looping on
66 //--------------------------------------------------------------------
67 //ProcessTracksAndParticles - "TracksAndParticles"
69 // it loops over both, tracks(reconstructed) and particles(simulated)
70 // all function gethered in all 3 lists are called for each (double)pair
72 //ProcessTracks - "Tracks"
73 // it loops only on tracks(reconstructed),
74 // functions ONLY from fTrackFunctions list are called
76 //ProcessParticles - "Particles"
77 // it loops only on particles(simulated),
78 // functions ONLY from fParticleAndTrackFunctions list are called
83 Error("Process","The reader is not set");
88 const char *oT = strstr(option,"Tracks");
89 const char *oP = strstr(option,"Particles");
93 if (fReader->GetNumberOfPartEvents() <1)
95 Error("Process","There is no Particles. Maybe change the option?");
98 if (fReader->GetNumberOfTrackEvents() <1)
100 Error("Process","There is no Tracks. Maybe change the option?");
104 if ( RunCoherencyCheck() )
107 "Coherency check not passed. Maybe change the option?\n");
110 ProcessTracksAndParticles();
116 if (fReader->GetNumberOfTrackEvents() <1)
118 Error("Process","There is no data to analyze.");
127 if (fReader->GetNumberOfPartEvents() <1)
129 Error("Process","There is no data to analyze.");
138 /*************************************************************************************/
140 void AliHBTAnalysis::ProcessTracksAndParticles()
143 //In order to minimize calling AliRun::GetEvent (we need at one time particles from different events),
144 //the loops are splited
147 AliHBTParticle * part1, * part2;
148 AliHBTParticle * track1, * track2;
150 AliHBTEvent * trackEvent, *partEvent;
151 AliHBTEvent * trackEvent2,*partEvent2;
153 // Int_t N1, N2, N=0; //number of particles in current event(we prcess two events in one time)
155 Int_t Nev = fReader->GetNumberOfTrackEvents();
157 /***************************************/
158 /****** Looping same events ********/
159 /****** filling numerators ********/
160 /***************************************/
161 AliHBTPair * trackpair = new AliHBTPair();
162 AliHBTPair * partpair = new AliHBTPair();
164 AliHBTPair * tmptrackpair;//temprary pointers to pairs
165 AliHBTPair * tmppartpair;
167 for (Int_t i = 0;i<Nev;i++)
169 partEvent= fReader->GetParticleEvent(i);
170 trackEvent = fReader->GetTrackEvent(i);
172 if (!partEvent) continue;
176 for (Int_t j = 0; j<partEvent->GetNumberOfParticles() ; j++)
178 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<i<<endl;
180 part1= partEvent->GetParticle(j);
181 track1= trackEvent->GetParticle(j);
183 for (Int_t k =j+1; k < partEvent->GetNumberOfParticles() ; k++)
185 part2= partEvent->GetParticle(k);
186 partpair->SetParticles(part1,part2);
188 track2= trackEvent->GetParticle(k);
189 trackpair->SetParticles(track1,track2);
191 if(fPairCut->Pass(partpair) || (fPairCut->Pass(trackpair))) //check pair cut
192 { //do not meets crietria of the pair cut, try with swaped pairs
193 if( ( fPairCut->Pass(partpair->GetSwapedPair()) ) || ( fPairCut->Pass(trackpair->GetSwapedPair()) ) )
194 continue; //swaped pairs do not meet criteria of pair cut as well, take next particle
196 { //swaped pair meets all the criteria
197 tmppartpair = partpair->GetSwapedPair();
198 tmptrackpair = trackpair->GetSwapedPair();
203 {//meets criteria of the pair cut
204 tmptrackpair = trackpair;
205 tmppartpair = partpair;
208 for(ii = 0;ii<fNParticleFunctions;ii++)
209 fParticleFunctions[ii]->ProcessSameEventParticles(tmppartpair);
211 for(ii = 0;ii<fNTrackFunctions;ii++)
212 fTrackFunctions[ii]->ProcessSameEventParticles(tmptrackpair);
214 for(ii = 0;ii<fNParticleAndTrackFunctions;ii++)
215 fParticleAndTrackFunctions[ii]->ProcessSameEventParticles(tmptrackpair,tmppartpair);
220 /***************************************/
221 /***** Filling denominators *********/
222 /***************************************/
223 for (Int_t i = 0;i<Nev;i++) //In each event ....
226 partEvent= fReader->GetParticleEvent(i);
227 if (!partEvent) continue;
229 trackEvent = fReader->GetTrackEvent(i);
233 for (Int_t j = 0; j< partEvent->GetNumberOfParticles(); j++) // ... Loop over all particles ...
235 // if (N>MAXCOMB) break;
237 part1= partEvent->GetParticle(j);
239 track1= trackEvent->GetParticle(j);
241 // for (Int_t k = i+1; k<Nev;k++) // ... Loop over all proceeding events ...
244 if ( (i+2) < Nev) NNN = i+2;
247 for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
250 partEvent2= fReader->GetParticleEvent(k);
251 if (!partEvent2) continue;
253 trackEvent2 = fReader->GetTrackEvent(k);
255 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<k<<endl;
257 for(Int_t l = 0; l<partEvent2->GetNumberOfParticles();l++) // ... on all particles
260 // if (N>MAXCOMB) break;
262 part2= partEvent2->GetParticle(l);
263 partpair->SetParticles(part1,part2);
265 track2= trackEvent2->GetParticle(l);
266 trackpair->SetParticles(track1,track2);
268 if( (fPairCut->Pass(partpair)) || (fPairCut->Pass(trackpair)) ) //check pair cut
269 { //do not meets crietria of the
270 if( ( fPairCut->Pass(partpair->GetSwapedPair()) ) || ( fPairCut->Pass(trackpair->GetSwapedPair()) ) )
274 tmppartpair = partpair->GetSwapedPair();
275 tmptrackpair = trackpair->GetSwapedPair();
279 {//meets criteria of the pair cut
280 tmptrackpair = trackpair;
281 tmppartpair = partpair;
284 for(ii = 0;ii<fNParticleFunctions;ii++)
285 fParticleFunctions[ii]->ProcessDiffEventParticles(tmppartpair);
287 for(ii = 0;ii<fNTrackFunctions;ii++)
288 fTrackFunctions[ii]->ProcessDiffEventParticles(tmptrackpair);
290 for(ii = 0;ii<fNParticleAndTrackFunctions;ii++)
291 fParticleAndTrackFunctions[ii]->ProcessDiffEventParticles(tmptrackpair,tmppartpair);
294 }//for(Int_t l = 0; l<N2;l++) // ... on all particles
295 }//for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
300 /***************************************/
304 /*************************************************************************************/
306 void AliHBTAnalysis::ProcessTracks()
308 //In order to minimize calling AliRun::GetEvent (we need at one time particles from different events),
309 //the loops are splited
310 AliHBTParticle * track1, * track2;
312 AliHBTEvent * trackEvent;
313 AliHBTEvent * trackEvent2;
315 // Int_t N1, N2, N=0; //number of particles in current event(we prcess two events in one time)
317 Int_t Nev = fReader->GetNumberOfTrackEvents();
319 /***************************************/
320 /****** Looping same events ********/
321 /****** filling numerators ********/
322 /***************************************/
323 AliHBTPair * trackpair = new AliHBTPair();
324 AliHBTPair * tmptrackpair; //temporary pointer
326 for (Int_t i = 0;i<Nev;i++)
328 trackEvent = fReader->GetTrackEvent(i);
329 if (!trackEvent) continue;
332 for (Int_t j = 0; j<trackEvent->GetNumberOfParticles() ; j++)
334 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<i<<endl;
336 track1= trackEvent->GetParticle(j);
338 for (Int_t k =j+1; k < trackEvent->GetNumberOfParticles() ; k++)
340 track2= trackEvent->GetParticle(k);
341 trackpair->SetParticles(track1,track2);
342 if(fPairCut->Pass(trackpair)) //check pair cut
343 { //do not meets crietria of the
344 if( fPairCut->Pass(trackpair->GetSwapedPair()) ) continue;
345 else tmptrackpair = trackpair->GetSwapedPair();
349 tmptrackpair = trackpair;
353 for(ii = 0;ii<fNTrackFunctions;ii++)
354 fTrackFunctions[ii]->ProcessSameEventParticles(tmptrackpair);
361 /***************************************/
362 /***** Filling diff histogram *********/
363 /***************************************/
364 for (Int_t i = 0;i<Nev;i++) //In each event ....
366 trackEvent = fReader->GetTrackEvent(i);
367 if (!trackEvent) continue;
370 for (Int_t j = 0; j< trackEvent->GetNumberOfParticles(); j++) // ... Loop over all particles ...
372 // if (N>MAXCOMB) break;
374 track1= trackEvent->GetParticle(j);
376 // for (Int_t k = i+1; k<Nev;k++) // ... Loop over all proceeding events ...
379 if ( (i+2) < Nev) NNN = i+2;
382 for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
385 trackEvent2 = fReader->GetTrackEvent(k);
386 if (!trackEvent2) continue;
388 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<k<<endl;
390 for(Int_t l = 0; l<trackEvent2->GetNumberOfParticles();l++) // ... on all particles
393 // if (N>MAXCOMB) break;
394 track2= trackEvent2->GetParticle(l);
395 trackpair->SetParticles(track1,track2);
397 if(fPairCut->Pass(trackpair)) //check pair cut
398 { //do not meets crietria of the
399 if( fPairCut->Pass(trackpair->GetSwapedPair()) ) continue;
400 else tmptrackpair = trackpair->GetSwapedPair();
404 tmptrackpair = trackpair;
407 for(ii = 0;ii<fNTrackFunctions;ii++)
408 fTrackFunctions[ii]->ProcessDiffEventParticles(tmptrackpair);
410 }//for(Int_t l = 0; l<N2;l++) // ... on all particles
411 }//for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
416 /***************************************/
421 /*************************************************************************************/
423 void AliHBTAnalysis::ProcessParticles()
425 //In order to minimize calling AliRun::GetEvent (we need at one time particles from different events),
426 //the loops are splited
427 AliHBTParticle * part1, * part2;
429 AliHBTEvent * partEvent;
430 AliHBTEvent * partEvent2;
432 AliHBTPair * partpair = new AliHBTPair();
433 AliHBTPair * tmppartpair; //temporary pointer to the pair
435 // Int_t N1, N2, N=0; //number of particles in current event(we prcess two events in one time)
437 Int_t Nev = fReader->GetNumberOfPartEvents();
439 /***************************************/
440 /****** Looping same events ********/
441 /****** filling numerators ********/
442 /***************************************/
443 for (Int_t i = 0;i<Nev;i++)
445 partEvent= fReader->GetParticleEvent(i);
446 if (!partEvent) continue;
449 for (Int_t j = 0; j<partEvent->GetNumberOfParticles() ; j++)
451 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<i<<endl;
453 part1= partEvent->GetParticle(j);
455 for (Int_t k =j+1; k < partEvent->GetNumberOfParticles() ; k++)
457 part2= partEvent->GetParticle(k);
458 partpair->SetParticles(part1,part2);
460 if( fPairCut->Pass(partpair) ) //check pair cut
461 { //do not meets crietria of the pair cut, try with swaped pairs
462 if( fPairCut->Pass(partpair->GetSwapedPair() ) )
463 continue; //swaped pairs do not meet criteria of pair cut as well, take next particle
465 { //swaped pair meets all the criteria
466 tmppartpair = partpair->GetSwapedPair();
471 tmppartpair = partpair;
476 for(ii = 0;ii<fNParticleFunctions;ii++)
477 fParticleFunctions[ii]->ProcessSameEventParticles(tmppartpair);
482 /***************************************/
483 /***** Filling diff histogram *********/
484 /***************************************/
485 for (Int_t i = 0;i<Nev;i++) //In each event ....
487 partEvent= fReader->GetParticleEvent(i);
488 if (!partEvent) continue;
492 for (Int_t j = 0; j< partEvent->GetNumberOfParticles(); j++) // ... Loop over all particles ...
494 // if (N>MAXCOMB) break;
496 part1= partEvent->GetParticle(j);
498 // for (Int_t k = i+1; k<Nev;k++) // ... Loop over all proceeding events ...
501 if ( (i+2) < Nev) NNN = i+2; //loop over next event
504 for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
507 partEvent2= fReader->GetParticleEvent(k);
508 if (!partEvent2) continue;
510 if ( (j%100) == 0) cout<<"Mixing particle "<<j<<" from event "<<i<<" with particles from event "<<k<<endl;
512 for(Int_t l = 0; l<partEvent2->GetNumberOfParticles();l++) // ... on all particles
515 // if (N>MAXCOMB) break;
516 part2= partEvent2->GetParticle(l);
517 partpair->SetParticles(part1,part2);
519 if(fPairCut->Pass(partpair)) //check pair cut
520 { //do not meets crietria of the
521 if( fPairCut->Pass(partpair->GetSwapedPair()) ) continue;
522 else tmppartpair = partpair->GetSwapedPair();
526 tmppartpair = partpair;
529 for(ii = 0;ii<fNParticleFunctions;ii++)
530 fParticleFunctions[ii]->ProcessDiffEventParticles(tmppartpair);
532 }//for(Int_t l = 0; l<N2;l++) // ... on all particles
533 }//for (Int_t k = i+1; k<NNN;k++) // ... Loop over next event
538 /***************************************/
543 /*************************************************************************************/
546 void AliHBTAnalysis::WriteFunctions()
549 for(ii = 0;ii<fNParticleFunctions;ii++)
550 fParticleFunctions[ii]->Write();
552 for(ii = 0;ii<fNTrackFunctions;ii++)
553 fTrackFunctions[ii]->Write();
555 for(ii = 0;ii<fNParticleAndTrackFunctions;ii++)
556 fParticleAndTrackFunctions[ii]->Write();
558 /*************************************************************************************/
560 void AliHBTAnalysis::SetGlobalPairCut(AliHBTPairCut* cut)
564 Error("AliHBTAnalysis::SetGlobalPairCut","Pointer is NULL. Ignoring");
567 fPairCut = (AliHBTPairCut*)cut->Clone();
570 /*************************************************************************************/
572 void AliHBTAnalysis::AddTrackFunction(AliHBTOnePairFctn* f)
574 if (f == 0x0) return;
575 if (fNTrackFunctions == fgkFctnArraySize)
577 Error("AliHBTAnalysis::AddTrackFunction","Can not add this function, not enough place in the array.");
579 fTrackFunctions[fNTrackFunctions] = f;
582 /*************************************************************************************/
584 void AliHBTAnalysis::AddParticleFunction(AliHBTOnePairFctn* f)
586 if (f == 0x0) return;
588 if (fNParticleFunctions == fgkFctnArraySize)
590 Error("AliHBTAnalysis::AddParticleFunction","Can not add this function, not enough place in the array.");
592 fParticleFunctions[fNParticleFunctions] = f;
593 fNParticleFunctions++;
597 void AliHBTAnalysis::AddParticleAndTrackFunction(AliHBTTwoPairFctn* f)
599 if (f == 0x0) return;
600 if (fNParticleAndTrackFunctions == fgkFctnArraySize)
602 Error("AliHBTAnalysis::AddParticleAndTrackFunction","Can not add this function, not enough place in the array.");
604 fParticleAndTrackFunctions[fNParticleAndTrackFunctions] = f;
605 fNParticleAndTrackFunctions++;
609 /*************************************************************************************/
612 /*************************************************************************************/
614 Bool_t AliHBTAnalysis::RunCoherencyCheck()
616 //Checks if both HBTRuns are similar
617 //return true if error found
618 //if they seem to be OK return false
620 cout<<"Checking HBT Runs Coherency"<<endl;
622 cout<<"Number of events ..."; fflush(stdout);
624 if (fReader->GetNumberOfPartEvents() == fReader->GetNumberOfTrackEvents() ) //check whether there is the same number of events
626 cout<<"OK. "<<fReader->GetNumberOfTrackEvents()<<" found"<<endl;
629 { //if not the same - ERROR
630 Error("AliHBTAnalysis::RunCoherencyCheck()",
631 "Number of simulated events (%d) is not equal to number of reconstructed events(%d)",
632 fReader->GetNumberOfPartEvents(),fReader->GetNumberOfTrackEvents());
636 cout<<"Checking number of Particles AND Particles Types in each event ...";fflush(stdout);
638 AliHBTEvent *partEvent;
639 AliHBTEvent *trackEvent;
640 for( i = 0; i<fReader->GetNumberOfTrackEvents();i++)
642 partEvent= fReader->GetParticleEvent(i); //gets the "ith" event
643 trackEvent = fReader->GetTrackEvent(i);
645 if ( (partEvent == 0x0) && (partEvent == 0x0) ) continue;
646 if ( (partEvent == 0x0) || (partEvent == 0x0) )
648 Error("AliHBTAnalysis::RunCoherencyCheck()",
649 "One event is NULL and the other one not. Event Number %d",i);
653 if ( partEvent->GetNumberOfParticles() != trackEvent->GetNumberOfParticles() )
655 Error("AliHBTAnalysis::RunCoherencyCheck()",
656 "Event %d: Number of simulated particles (%d) not equal to number of reconstructed tracks (%d)",
657 i,partEvent->GetNumberOfParticles() , trackEvent->GetNumberOfParticles());
661 for (Int_t j = 0; j<partEvent->GetNumberOfParticles(); j++)
663 if( partEvent->GetParticle(j)->GetPdgCode() != trackEvent->GetParticle(j)->GetPdgCode() )
665 Error("AliHBTAnalysis::RunCoherencyCheck()",
666 "Event %d: Particle %d: PID of simulated particle (%d) not the same of reconstructed track (%d)",
667 i,j, partEvent->GetParticle(j)->GetPdgCode(),trackEvent->GetParticle(j)->GetPdgCode() );
674 cout<<" Everything looks OK"<<endl;
679 /*************************************************************************************/
682 /*************************************************************************************/