AliPhysics  8bb951a (8bb951a)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliParticleContainer.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 #include <algorithm>
16 #include <iostream>
17 #include <vector>
18 #include <TClonesArray.h>
19 
20 #include "AliVEvent.h"
21 #include "AliLog.h"
22 
23 #include "AliTLorentzVector.h"
24 #include "AliParticleContainer.h"
25 
29 
35  fMinDistanceTPCSectorEdge(-1),
36  fCharge(-1),
37  fGeneratorIndex(-1)
38 {
39  fBaseClassName = "AliVParticle";
40  SetClassName("AliVParticle");
41 }
42 
48  AliEmcalContainer(name),
49  fMinDistanceTPCSectorEdge(-1),
50  fCharge(-1),
51  fGeneratorIndex(-1)
52 {
53  fBaseClassName = "AliVParticle";
54  SetClassName("AliVParticle");
55 }
56 
63 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
64 {
65  TString option(opt);
66  option.ToLower();
67 
68  Int_t tempID = fCurrentID;
70 
71  AliVParticle *partMax = GetNextAcceptParticle();
72  AliVParticle *part = 0;
73 
74  if (option.Contains("p")) {
75  while ((part = GetNextAcceptParticle())) {
76  if (part->P() > partMax->P()) partMax = part;
77  }
78  }
79  else {
80  while ((part = GetNextAcceptParticle())) {
81  if (part->Pt() > partMax->Pt()) partMax = part;
82  }
83  }
84 
85  fCurrentID = tempID;
86 
87  return partMax;
88 }
89 
95 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
96 {
97  //
98  if (i == -1) i = fCurrentID;
99  if (i < 0 || i >= this->fClArray->GetEntriesFast()) return 0;
100  AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
101  return vp;
102 }
103 
110 AliVParticle* AliParticleContainer::GetAcceptParticle(Int_t i) const
111 {
112  UInt_t rejectionReason = 0;
113  if (i == -1) i = fCurrentID;
114  if (AcceptParticle(i, rejectionReason)) {
115  return GetParticle(i);
116  }
117  else {
118  AliDebug(2,"Particle not accepted.");
119  return 0;
120  }
121 }
122 
130 {
131  const Int_t n = GetNEntries();
132  AliVParticle *p = 0;
133  do {
134  fCurrentID++;
135  if (fCurrentID >= n) break;
137  } while (!p);
138 
139  return p;
140 }
141 
149 {
150  const Int_t n = GetNEntries();
151  AliVParticle *p = 0;
152  do {
153  fCurrentID++;
154  if (fCurrentID >= n) break;
155  p = GetParticle(fCurrentID);
156  } while (!p);
157 
158  return p;
159 }
160 
170 Bool_t AliParticleContainer::GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle* part, Double_t mass) const
171 {
172  if (part) {
173  if (mass < 0) mass = part->M();
174  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
175  return kTRUE;
176  }
177  else {
178  mom.SetPtEtaPhiM(0, 0, 0, 0);
179  return kFALSE;
180  }
181 }
182 
190 Bool_t AliParticleContainer::GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle* part) const
191 {
192  return GetMomentumFromParticle(mom,part,fMassHypothesis);
193 }
194 
204 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
205 {
206  if (i == -1) i = fCurrentID;
207  AliVParticle *vp = GetParticle(i);
208  return GetMomentumFromParticle(mom, vp);
209 }
210 
220 Bool_t AliParticleContainer::GetNextMomentum(TLorentzVector &mom)
221 {
222  AliVParticle *vp = GetNextParticle();
223  return GetMomentumFromParticle(mom, vp);
224 }
225 
236 Bool_t AliParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
237 {
238  if (i == -1) i = fCurrentID;
239  AliVParticle *vp = GetAcceptParticle(i);
240  return GetMomentumFromParticle(mom, vp);
241 }
242 
253 {
254  AliVParticle *vp = GetNextAcceptParticle();
255  return GetMomentumFromParticle(mom, vp);
256 }
257 
268 Bool_t AliParticleContainer::AcceptParticle(const AliVParticle *vp, UInt_t &rejectionReason) const
269 {
270  Bool_t r = ApplyParticleCuts(vp, rejectionReason);
271  if (!r) return kFALSE;
272 
273  AliTLorentzVector mom;
274 
275  Int_t id = fClArray->IndexOf(vp);
276  if (id >= 0) {
277  GetMomentum(mom, id);
278  }
279  else {
280  GetMomentumFromParticle(mom, vp);
281  }
282 
283  return ApplyKinematicCuts(mom, rejectionReason);
284 }
285 
296 Bool_t AliParticleContainer::AcceptParticle(Int_t i, UInt_t &rejectionReason) const
297 {
298  Bool_t r = ApplyParticleCuts(GetParticle(i), rejectionReason);
299  if (!r) return kFALSE;
300 
301  AliTLorentzVector mom;
302  GetMomentum(mom, i);
303 
304  return ApplyKinematicCuts(mom, rejectionReason);
305 }
306 
319 Bool_t AliParticleContainer::ApplyParticleCuts(const AliVParticle* vp, UInt_t &rejectionReason) const
320 {
321  if (!vp) {
322  rejectionReason |= kNullObject;
323  return kFALSE;
324  }
325 
326  if (vp->TestBits(fBitMap) != (Int_t)fBitMap) {
327  rejectionReason |= kBitMapCut;
328  return kFALSE;
329  }
330 
331  if (fMinMCLabel >= 0 && TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
332  rejectionReason |= kMCLabelCut;
333  return kFALSE;
334  }
335 
336  if (fMaxMCLabel >= 0 && TMath::Abs(vp->GetLabel()) < fMaxMCLabel) {
337  rejectionReason |= kMCLabelCut;
338  return kFALSE;
339  }
340 
341  if (fCharge>=0 && fCharge != vp->Charge()) {
342  rejectionReason |= kChargeCut;
343  return kFALSE;
344  }
345 
346  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
347  rejectionReason |= kMCGeneratorCut;
348  return kFALSE;
349  }
350 
351  return kTRUE;
352 }
353 
365 Bool_t AliParticleContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
366 {
368  const Double_t pi = TMath::Pi();
369  const Double_t kSector = pi/9;
370  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
371  if(phiDist<fMinDistanceTPCSectorEdge) {
372  rejectionReason |= kMinDistanceTPCSectorEdgeCut;
373  return kFALSE;
374  }
375  }
376 
377  return AliEmcalContainer::ApplyKinematicCuts(mom, rejectionReason);
378 }
379 
387 {
388  Int_t nPart = 0;
389  for(int ipart = 0; ipart < this->GetNParticles(); ipart++){
390  UInt_t rejectionReason = 0;
391  if(this->AcceptParticle(ipart, rejectionReason)) nPart++;
392  }
393  return nPart;
394 }
395 
402 {
403  static TString trackString;
404 
405  if (GetMinPt() == 0) {
406  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
407  }
408  else if (GetMinPt() < 1.0) {
409  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
410  }
411  else {
412  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
413  }
414 
415  return trackString.Data();
416 }
417 
424  return all_iterator(this, 0, true);
425 }
426 
433  return all_iterator(this, this->GetNParticles(), true);
434 }
435 
442  return all_iterator(this, this->GetNParticles(), false);
443 }
444 
451  return all_iterator(this, -1, false);
452 }
459  return accept_iterator(this, 0, true);
460 }
461 
468  return accept_iterator(this, this->GetNAcceptedParticles(), true);
469 }
470 
477  return accept_iterator(this, this->GetNAcceptedParticles()-1, false);
478 }
479 
486  return accept_iterator(this, -1, false);
487 }
488 
494 
511  const AliParticleContainer *cont,
512  int start,
513  bool forward):
514  fkContainer(cont),
515  fAcceptIndices(),
516  fCurrentPos(start),
517  fForward(forward)
518 {
520  UInt_t rejection = 0;
521  Int_t mappos = 0;
522  for(int i = 0; i < fkContainer->GetNEntries(); i++){
523  if(fkContainer->AcceptParticle(i, rejection)){
524  fAcceptIndices[mappos++] = i;
525  }
526  }
527 }
528 
535  fkContainer(other.fkContainer),
536  fAcceptIndices(other.fAcceptIndices),
537  fCurrentPos(other.fCurrentPos),
538  fForward(other.fForward)
539 {
540 }
541 
549  if(this != &other){
550  fkContainer = other.fkContainer;
551  fAcceptIndices = other.fAcceptIndices;
552  fCurrentPos = other.fCurrentPos;
553  fForward = other.fForward;
554  }
555  return *this;
556 }
557 
565  return fCurrentPos != other.fCurrentPos;
566 }
567 
574  if(fForward){
575  fCurrentPos++;
576  } else {
577  fCurrentPos--;
578  }
579  return *this;
580 }
581 
590  this->operator++();
591  return result;
592 }
593 
600  if(fForward){
601  fCurrentPos--;
602  } else {
603  fCurrentPos++;
604  }
605  return *this;
606 }
607 
616  this->operator++();
617  return result;
618 }
619 
626  if(fCurrentPos < 0 || fCurrentPos >= fAcceptIndices.GetSize()){
627  return NULL;
628  }
629  return fkContainer->GetParticle(fAcceptIndices[fCurrentPos]);
630 }
631 
637 
652  const AliParticleContainer *cont,
653  int startpos,
654  bool forward):
655  fkContainer(cont),
656  fCurrentPos(startpos),
657  fForward(forward)
658 {
659 }
660 
667  fkContainer(other.fkContainer),
668  fCurrentPos(other.fCurrentPos),
669  fForward(other.fForward)
670 {
671 }
672 
680  if(&other != this){
681  fkContainer = other.fkContainer;
682  fCurrentPos = other.fCurrentPos;
683  fForward = other.fForward;
684  }
685  return *this;
686 }
687 
695  return other.fCurrentPos != fCurrentPos;
696 }
697 
704  if(fForward){
705  fCurrentPos++;
706  } else {
707  fCurrentPos--;
708  }
709  return *this;
710 }
711 
719  all_iterator tmp(*this);
720  operator++();
721  return tmp;
722 }
723 
730  if(fForward){
731  fCurrentPos--;
732  } else {
733  fCurrentPos++;
734  }
735  return *this;
736 }
737 
745  all_iterator tmp(*this);
746  operator--();
747  return tmp;
748 }
749 
756  if(fCurrentPos >= 0 && fCurrentPos < fkContainer->GetNParticles())
757  return fkContainer->GetParticle(fCurrentPos);
758  return NULL;
759 }
760 
761 /******************************************
762  * Unit tests *
763  ******************************************/
764 
765 int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose){
766  std::vector<AliVParticle *> reference, variation;
767  AliVParticle *test = NULL;
768  for(int iclust = 0; iclust < cont->GetNParticles(); iclust++){
769  test = cont->GetParticle(iclust);
770  if(!iteratorType){
771  UInt_t rejectionReason = 0;
772  if(!cont->AcceptParticle(test, rejectionReason)) continue;
773  }
774  reference.push_back(test);
775  }
776 
777  if(!iteratorType){
778  // test accept iterator
779  for(AliParticleContainer::accept_iterator iter = cont->accept_begin(); iter != cont->accept_end(); ++iter){
780  variation.push_back(*iter);
781  }
782  } else {
783  // test all iterator
784  for(AliParticleContainer::all_iterator iter = cont->begin(); iter != cont->end(); ++iter){
785  variation.push_back(*iter);
786  }
787  }
788 
789  if(verbose) {
790  // Printing cluster addresses:
791  if(reference.size() < 30){
792  std::cout << "Paritcles in reference container: " << std::endl;
793  std::cout << "===========================================" << std::endl;
794  for(std::vector<AliVParticle *>::iterator refit = reference.begin(); refit != reference.end(); ++refit){
795  std::cout << "Address: " << *refit << std::endl;
796  }
797  }
798  if(variation.size() < 30){
799  std::cout << "Paritcles in test container: " << std::endl;
800  std::cout << "===========================================" << std::endl;
801  for(std::vector<AliVParticle *>::iterator varit = variation.begin(); varit != variation.end(); ++varit){
802  std::cout << "Address: " << *varit << std::endl;
803  }
804  }
805  }
806 
807  int testresult = 0;
808  // compare distributions: all particles in one vector needs to be found in the other vector and vice versa
809  bool failure = false;
810  // first test: cleck if all particles are found by the iterator
811  for(std::vector<AliVParticle *>::iterator clit = reference.begin(); clit != reference.end(); ++clit){
812  if(std::find(variation.begin(), variation.end(), *clit) == variation.end()) {
813  if(verbose)
814  std::cout << "Could not find particle with address " << *clit << " in test container" << std::endl;
815  failure = true;
816  break;
817  }
818  }
819  if(!failure){
820  // second test: check if there are no extra particles found
821  for(std::vector<AliVParticle *>::iterator clit = variation.begin(); clit != variation.end(); ++clit){
822  if(std::find(reference.begin(), reference.end(), *clit) == reference.end()) {
823  if(verbose)
824  std::cout << "Could not find particle with address " << *clit << " in reference container" << std::endl;
825  failure = true;
826  break;
827  }
828  }
829  if(failure) testresult = 2;
830  } else testresult = 1;
831  if(verbose) {
832  std::cout << "Unit test particle container, iterator type " << iteratorType << std::endl;
833  std::cout << "Number of expected particles: " << reference.size() << ", number of found particles: " << variation.size() << std::endl;
834  std::cout << "Test result: " << testresult << std::endl;
835  std::cout << "-----------------------------------------------------------------------" << std::endl;
836  }
837  return testresult;
838 }
all_iterator begin() const
const Double_t kSector
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
virtual AliVParticle * GetNextAcceptParticle()
int fCurrentPos
Current position inside the container.
virtual Bool_t GetMomentum(TLorentzVector &mom, Int_t i) const
all_iterator rend() const
const char * GetTitle() const
accept_iterator accept_begin() const
accept_iterator accept_rbegin() const
Double_t mass
UInt_t fBitMap
bitmap mask
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp, UInt_t &rejectionReason) const
TArrayI fAcceptIndices
Indices of accepted clusters.
Track too close to the TPC sector boundary.
all_iterator rbegin() const
virtual Bool_t GetNextMomentum(TLorentzVector &mom)
Container for particles within the EMCAL framework.
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom)
bool fForward
Direction, expressed in forward direction.
stl iterator over all clusters
bool operator!=(const all_iterator &other) const
Double_t GetMinPt() const
virtual AliVParticle * GetLeadingParticle(const char *opt="")
virtual AliVParticle * GetParticle(Int_t i=-1) const
Base class for container structures within the EMCAL framework.
const AliParticleContainer * fkContainer
Container iterated over.
virtual AliVParticle * GetAcceptParticle(Int_t i=-1) const
accept_iterator accept_rend() const
Short_t fCharge
select particles with charge=fCharge
int fCurrentPos
Current position inside the container.
accept_iterator accept_end() const
virtual Bool_t AcceptParticle(const AliVParticle *vp, UInt_t &rejectionReason) const
stl iterator over accepted clusters
Double_t fMinDistanceTPCSectorEdge
require minimum distance to edge of TPC sector edge
void SetClassName(const char *clname)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Int_t fMinMCLabel
minimum MC label
const TString & GetArrayName() const
Double_t fMassHypothesis
if < 0 it will use a PID mass when available
Short_t fGeneratorIndex
select MC particles with generator index (default = -1 = switch off selection)
const AliParticleContainer * fkContainer
Container iterated over.
bool fForward
Direction, expressed in forward direction.
all_iterator end() const
virtual Bool_t GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle *part, Double_t mass) const
Particle charge did not match.
TString fBaseClassName
name of the base class that this container can handle
Int_t fMaxMCLabel
maximum MC label
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
bool operator!=(const accept_iterator &other) const
accept_iterator & operator=(const accept_iterator &other)
int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose)
TClonesArray * fClArray
! Pointer to array in input event
Int_t GetNEntries() const
const Double_t pi
Int_t GetNAcceptedParticles() const
Int_t fCurrentID
! current ID for automatic loops
all_iterator & operator=(const all_iterator &other)
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
void ResetCurrentID(Int_t i=-1)
virtual AliVParticle * GetNextParticle()