AliPhysics  3c9d42f (3c9d42f)
 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  fClassName = "AliVParticle";
40 }
41 
47  AliEmcalContainer(name),
48  fMinDistanceTPCSectorEdge(-1),
49  fCharge(-1),
50  fGeneratorIndex(-1)
51 {
52  fClassName = "AliVParticle";
53 }
54 
61 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
62 {
63  TString option(opt);
64  option.ToLower();
65 
66  Int_t tempID = fCurrentID;
68 
69  AliVParticle *partMax = GetNextAcceptParticle();
70  AliVParticle *part = 0;
71 
72  if (option.Contains("p")) {
73  while ((part = GetNextAcceptParticle())) {
74  if (part->P() > partMax->P()) partMax = part;
75  }
76  }
77  else {
78  while ((part = GetNextAcceptParticle())) {
79  if (part->Pt() > partMax->Pt()) partMax = part;
80  }
81  }
82 
83  fCurrentID = tempID;
84 
85  return partMax;
86 }
87 
93 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
94 {
95  //
96  if (i == -1) i = fCurrentID;
97  if (i < 0 || i >= this->fClArray->GetEntriesFast()) return 0;
98  AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
99  return vp;
100 }
101 
108 AliVParticle* AliParticleContainer::GetAcceptParticle(Int_t i) const
109 {
110  UInt_t rejectionReason = 0;
111  if (i == -1) i = fCurrentID;
112  if (AcceptParticle(i, rejectionReason)) {
113  return GetParticle(i);
114  }
115  else {
116  AliDebug(2,"Particle not accepted.");
117  return 0;
118  }
119 }
120 
128 {
129  const Int_t n = GetNEntries();
130  AliVParticle *p = 0;
131  do {
132  fCurrentID++;
133  if (fCurrentID >= n) break;
135  } while (!p);
136 
137  return p;
138 }
139 
147 {
148  const Int_t n = GetNEntries();
149  AliVParticle *p = 0;
150  do {
151  fCurrentID++;
152  if (fCurrentID >= n) break;
153  p = GetParticle(fCurrentID);
154  } while (!p);
155 
156  return p;
157 }
158 
168 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, const AliVParticle* part, Double_t mass) const
169 {
170  if (part) {
171  if (mass < 0) mass = part->M();
172  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
173  return kTRUE;
174  }
175  else {
176  mom.SetPtEtaPhiM(0, 0, 0, 0);
177  return kFALSE;
178  }
179 }
180 
188 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, const AliVParticle* part) const
189 {
190  return GetMomentum(mom,part,fMassHypothesis);
191 }
192 
202 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
203 {
204  Double_t mass = fMassHypothesis;
205 
206  if (i == -1) i = fCurrentID;
207  AliVParticle *vp = GetParticle(i);
208  if (vp) {
209  if (mass < 0) mass = vp->M();
210  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
211  return kTRUE;
212  }
213  else {
214  mom.SetPtEtaPhiM(0, 0, 0, 0);
215  return kFALSE;
216  }
217 }
218 
228 Bool_t AliParticleContainer::GetNextMomentum(TLorentzVector &mom)
229 {
230  Double_t mass = fMassHypothesis;
231 
232  AliVParticle *vp = GetNextParticle();
233  if (vp) {
234  if (mass < 0) mass = vp->M();
235  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
236  return kTRUE;
237  }
238  else {
239  mom.SetPtEtaPhiM(0, 0, 0, 0);
240  return kFALSE;
241  }
242 }
243 
254 Bool_t AliParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
255 {
256  Double_t mass = fMassHypothesis;
257 
258  if (i == -1) i = fCurrentID;
259  AliVParticle *vp = GetAcceptParticle(i);
260  if (vp) {
261  if (mass < 0) mass = vp->M();
262  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
263  return kTRUE;
264  }
265  else {
266  mom.SetPtEtaPhiM(0, 0, 0, 0);
267  return kFALSE;
268  }
269 }
270 
281 {
282  Double_t mass = fMassHypothesis;
283 
284  AliVParticle *vp = GetNextAcceptParticle();
285  if (vp) {
286  if (mass < 0) mass = vp->M();
287  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
288  return kTRUE;
289  }
290  else {
291  mom.SetPtEtaPhiM(0, 0, 0, 0);
292  return kFALSE;
293  }
294 }
295 
306 Bool_t AliParticleContainer::AcceptParticle(const AliVParticle *vp, UInt_t &rejectionReason) const
307 {
308  Bool_t r = ApplyParticleCuts(vp, rejectionReason);
309  if (!r) return kFALSE;
310 
311  AliTLorentzVector mom;
312 
313  Int_t id = fClArray->IndexOf(vp);
314  if (id >= 0) {
315  GetMomentum(mom, id);
316  }
317  else {
318  GetMomentum(mom, vp);
319  }
320 
321  return ApplyKinematicCuts(mom, rejectionReason);
322 }
323 
334 Bool_t AliParticleContainer::AcceptParticle(Int_t i, UInt_t &rejectionReason) const
335 {
336  Bool_t r = ApplyParticleCuts(GetParticle(i), rejectionReason);
337  if (!r) return kFALSE;
338 
339  AliTLorentzVector mom;
340  GetMomentum(mom, i);
341 
342  return ApplyKinematicCuts(mom, rejectionReason);
343 }
344 
357 Bool_t AliParticleContainer::ApplyParticleCuts(const AliVParticle* vp, UInt_t &rejectionReason) const
358 {
359  if (!vp) {
360  rejectionReason |= kNullObject;
361  return kFALSE;
362  }
363 
364  if (vp->TestBits(fBitMap) != (Int_t)fBitMap) {
365  rejectionReason |= kBitMapCut;
366  return kFALSE;
367  }
368 
369  if (fMinMCLabel >= 0 && TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
370  rejectionReason |= kMCLabelCut;
371  return kFALSE;
372  }
373 
374  if (fMaxMCLabel >= 0 && TMath::Abs(vp->GetLabel()) < fMaxMCLabel) {
375  rejectionReason |= kMCLabelCut;
376  return kFALSE;
377  }
378 
379  if (fCharge>=0 && fCharge != vp->Charge()) {
380  rejectionReason |= kChargeCut;
381  return kFALSE;
382  }
383 
384  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
385  rejectionReason |= kMCGeneratorCut;
386  return kFALSE;
387  }
388 
389  return kTRUE;
390 }
391 
403 Bool_t AliParticleContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
404 {
406  const Double_t pi = TMath::Pi();
407  const Double_t kSector = pi/9;
408  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
409  if(phiDist<fMinDistanceTPCSectorEdge) {
410  rejectionReason |= kMinDistanceTPCSectorEdgeCut;
411  return kFALSE;
412  }
413  }
414 
415  return AliEmcalContainer::ApplyKinematicCuts(mom, rejectionReason);
416 }
417 
425 {
426  Int_t nPart = 0;
427  for(int ipart = 0; ipart < this->GetNParticles(); ipart++){
428  UInt_t rejectionReason = 0;
429  if(this->AcceptParticle(ipart, rejectionReason)) nPart++;
430  }
431  return nPart;
432 }
433 
438 void AliParticleContainer::SetClassName(const char *clname)
439 {
440  // Set the class name
441 
442  TClass cls(clname);
443  if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
444  else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
445 }
446 
453 {
454  static TString trackString;
455 
456  if (GetMinPt() == 0) {
457  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
458  }
459  else if (GetMinPt() < 1.0) {
460  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
461  }
462  else {
463  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
464  }
465 
466  return trackString.Data();
467 }
468 
475  return all_iterator(this, 0, true);
476 }
477 
484  return all_iterator(this, this->GetNParticles(), true);
485 }
486 
493  return all_iterator(this, this->GetNParticles(), false);
494 }
495 
502  return all_iterator(this, -1, false);
503 }
510  return accept_iterator(this, 0, true);
511 }
512 
519  return accept_iterator(this, this->GetNAcceptedParticles(), true);
520 }
521 
528  return accept_iterator(this, this->GetNAcceptedParticles()-1, false);
529 }
530 
537  return accept_iterator(this, -1, false);
538 }
539 
545 
562  const AliParticleContainer *cont,
563  int start,
564  bool forward):
565  fkContainer(cont),
566  fAcceptIndices(),
567  fCurrentPos(start),
568  fForward(forward)
569 {
571  UInt_t rejection = 0;
572  Int_t mappos = 0;
573  for(int i = 0; i < fkContainer->GetNEntries(); i++){
574  if(fkContainer->AcceptParticle(i, rejection)){
575  fAcceptIndices[mappos++] = i;
576  }
577  }
578 }
579 
586  fkContainer(other.fkContainer),
587  fAcceptIndices(other.fAcceptIndices),
588  fCurrentPos(other.fCurrentPos),
589  fForward(other.fForward)
590 {
591 }
592 
600  if(this != &other){
601  fkContainer = other.fkContainer;
602  fAcceptIndices = other.fAcceptIndices;
603  fCurrentPos = other.fCurrentPos;
604  fForward = other.fForward;
605  }
606  return *this;
607 }
608 
616  return fCurrentPos != other.fCurrentPos;
617 }
618 
625  if(fForward){
626  fCurrentPos++;
627  } else {
628  fCurrentPos--;
629  }
630  return *this;
631 }
632 
641  this->operator++();
642  return result;
643 }
644 
651  if(fForward){
652  fCurrentPos--;
653  } else {
654  fCurrentPos++;
655  }
656  return *this;
657 }
658 
667  this->operator++();
668  return result;
669 }
670 
677  if(fCurrentPos < 0 || fCurrentPos >= fAcceptIndices.GetSize()){
678  return NULL;
679  }
680  return fkContainer->GetParticle(fAcceptIndices[fCurrentPos]);
681 }
682 
688 
703  const AliParticleContainer *cont,
704  int startpos,
705  bool forward):
706  fkContainer(cont),
707  fCurrentPos(startpos),
708  fForward(forward)
709 {
710 }
711 
718  fkContainer(other.fkContainer),
719  fCurrentPos(other.fCurrentPos),
720  fForward(other.fForward)
721 {
722 }
723 
731  if(&other != this){
732  fkContainer = other.fkContainer;
733  fCurrentPos = other.fCurrentPos;
734  fForward = other.fForward;
735  }
736  return *this;
737 }
738 
746  return other.fCurrentPos != fCurrentPos;
747 }
748 
755  if(fForward){
756  fCurrentPos++;
757  } else {
758  fCurrentPos--;
759  }
760  return *this;
761 }
762 
770  all_iterator tmp(*this);
771  operator++();
772  return tmp;
773 }
774 
781  if(fForward){
782  fCurrentPos--;
783  } else {
784  fCurrentPos++;
785  }
786  return *this;
787 }
788 
796  all_iterator tmp(*this);
797  operator--();
798  return tmp;
799 }
800 
807  if(fCurrentPos >= 0 && fCurrentPos < fkContainer->GetNParticles())
808  return fkContainer->GetParticle(fCurrentPos);
809  return NULL;
810 }
811 
812 /******************************************
813  * Unit tests *
814  ******************************************/
815 
816 int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose){
817  std::vector<AliVParticle *> reference, variation;
818  AliVParticle *test = NULL;
819  for(int iclust = 0; iclust < cont->GetNParticles(); iclust++){
820  test = cont->GetParticle(iclust);
821  if(!iteratorType){
822  UInt_t rejectionReason = 0;
823  if(!cont->AcceptParticle(test, rejectionReason)) continue;
824  }
825  reference.push_back(test);
826  }
827 
828  if(!iteratorType){
829  // test accept iterator
830  for(AliParticleContainer::accept_iterator iter = cont->accept_begin(); iter != cont->accept_end(); ++iter){
831  variation.push_back(*iter);
832  }
833  } else {
834  // test all iterator
835  for(AliParticleContainer::all_iterator iter = cont->begin(); iter != cont->end(); ++iter){
836  variation.push_back(*iter);
837  }
838  }
839 
840  if(verbose) {
841  // Printing cluster addresses:
842  if(reference.size() < 30){
843  std::cout << "Paritcles in reference container: " << std::endl;
844  std::cout << "===========================================" << std::endl;
845  for(std::vector<AliVParticle *>::iterator refit = reference.begin(); refit != reference.end(); ++refit){
846  std::cout << "Address: " << *refit << std::endl;
847  }
848  }
849  if(variation.size() < 30){
850  std::cout << "Paritcles in test container: " << std::endl;
851  std::cout << "===========================================" << std::endl;
852  for(std::vector<AliVParticle *>::iterator varit = variation.begin(); varit != variation.end(); ++varit){
853  std::cout << "Address: " << *varit << std::endl;
854  }
855  }
856  }
857 
858  int testresult = 0;
859  // compare distributions: all particles in one vector needs to be found in the other vector and vice versa
860  bool failure = false;
861  // first test: cleck if all particles are found by the iterator
862  for(std::vector<AliVParticle *>::iterator clit = reference.begin(); clit != reference.end(); ++clit){
863  if(std::find(variation.begin(), variation.end(), *clit) == variation.end()) {
864  if(verbose)
865  std::cout << "Could not find particle with address " << *clit << " in test container" << std::endl;
866  failure = true;
867  break;
868  }
869  }
870  if(!failure){
871  // second test: check if there are no extra particles found
872  for(std::vector<AliVParticle *>::iterator clit = variation.begin(); clit != variation.end(); ++clit){
873  if(std::find(reference.begin(), reference.end(), *clit) == reference.end()) {
874  if(verbose)
875  std::cout << "Could not find particle with address " << *clit << " in reference container" << std::endl;
876  failure = true;
877  break;
878  }
879  }
880  if(failure) testresult = 2;
881  } else testresult = 1;
882  if(verbose) {
883  std::cout << "Unit test particle container, iterator type " << iteratorType << std::endl;
884  std::cout << "Number of expected particles: " << reference.size() << ", number of found particles: " << variation.size() << std::endl;
885  std::cout << "Test result: " << testresult << std::endl;
886  std::cout << "-----------------------------------------------------------------------" << std::endl;
887  }
888  return testresult;
889 }
all_iterator begin() const
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
virtual AliVParticle * GetNextAcceptParticle()
int fCurrentPos
Current position inside the container.
all_iterator rend() const
const char * GetTitle() const
accept_iterator accept_begin() const
accept_iterator accept_rbegin() const
void SetClassName(const char *clname)
Double_t mass
UInt_t fBitMap
bitmap mask
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp, UInt_t &rejectionReason) const
TString fClassName
name of the class in the TClonesArray
virtual Bool_t GetMomentum(TLorentzVector &mom, const AliVParticle *part, Double_t mass) 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
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
Particle charge did not match.
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
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()