AliPhysics  1e965c0 (1e965c0)
 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 
34  AliEmcalContainer(),
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;
69  ResetCurrentID();
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;
136  p = GetAcceptParticle(fCurrentID);
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 AliParticleIterableContainer(this, false);
425 }
426 
433  return AliParticleIterableContainer(this, true);
434 }
435 
436 /******************************************
437  * Unit tests *
438  ******************************************/
439 
440 int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose){
441  std::vector<AliVParticle *> reference, variation;
442  AliVParticle *test = NULL;
443  for(int iclust = 0; iclust < cont->GetNParticles(); iclust++){
444  test = cont->GetParticle(iclust);
445  if(!iteratorType){
446  UInt_t rejectionReason = 0;
447  if(!cont->AcceptParticle(test, rejectionReason)) continue;
448  }
449  reference.push_back(test);
450  }
451 
452  if(!iteratorType){
453  // test accept iterator
454  for(AliParticleIterableContainer::iterator iter = cont->accept_begin(); iter != cont->accept_end(); ++iter){
455  variation.push_back(*iter);
456  }
457  } else {
458  // test all iterator
459  for(AliParticleIterableContainer::iterator iter = cont->begin(); iter != cont->end(); ++iter){
460  variation.push_back(*iter);
461  }
462  }
463 
464  if(verbose) {
465  // Printing cluster addresses:
466  if(reference.size() < 30){
467  std::cout << "Paritcles in reference container: " << std::endl;
468  std::cout << "===========================================" << std::endl;
469  for(std::vector<AliVParticle *>::iterator refit = reference.begin(); refit != reference.end(); ++refit){
470  std::cout << "Address: " << *refit << std::endl;
471  }
472  }
473  if(variation.size() < 30){
474  std::cout << "Paritcles in test container: " << std::endl;
475  std::cout << "===========================================" << std::endl;
476  for(std::vector<AliVParticle *>::iterator varit = variation.begin(); varit != variation.end(); ++varit){
477  std::cout << "Address: " << *varit << std::endl;
478  }
479  }
480  }
481 
482  int testresult = 0;
483  // compare distributions: all particles in one vector needs to be found in the other vector and vice versa
484  bool failure = false;
485  // first test: cleck if all particles are found by the iterator
486  for(std::vector<AliVParticle *>::iterator clit = reference.begin(); clit != reference.end(); ++clit){
487  if(std::find(variation.begin(), variation.end(), *clit) == variation.end()) {
488  if(verbose)
489  std::cout << "Could not find particle with address " << *clit << " in test container" << std::endl;
490  failure = true;
491  break;
492  }
493  }
494  if(!failure){
495  // second test: check if there are no extra particles found
496  for(std::vector<AliVParticle *>::iterator clit = variation.begin(); clit != variation.end(); ++clit){
497  if(std::find(reference.begin(), reference.end(), *clit) == reference.end()) {
498  if(verbose)
499  std::cout << "Could not find particle with address " << *clit << " in reference container" << std::endl;
500  failure = true;
501  break;
502  }
503  }
504  if(failure) testresult = 2;
505  } else testresult = 1;
506  if(verbose) {
507  std::cout << "Unit test particle container, iterator type " << iteratorType << std::endl;
508  std::cout << "Number of expected particles: " << reference.size() << ", number of found particles: " << variation.size() << std::endl;
509  std::cout << "Test result: " << testresult << std::endl;
510  std::cout << "-----------------------------------------------------------------------" << std::endl;
511  }
512  return testresult;
513 }
const Double_t kSector
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
virtual AliVParticle * GetNextAcceptParticle()
virtual Bool_t GetMomentum(TLorentzVector &mom, Int_t i) const
const char * GetTitle() const
const AliParticleIterableContainer all() const
Double_t mass
Int_t GetNParticles() const
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp, UInt_t &rejectionReason) const
AliParticleIterableContainer::iterator accept_end() const
AliParticleIterableContainer::iterator begin() const
AliEmcalIterableContainerT< AliVParticle > AliParticleIterableContainer
virtual Bool_t GetNextMomentum(TLorentzVector &mom)
bidirectional stl iterator over the EMCAL iterable container
Container for particles within the EMCAL framework.
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom)
AliParticleIterableContainer::iterator end() const
virtual AliVParticle * GetLeadingParticle(const char *opt="")
virtual AliVParticle * GetParticle(Int_t i=-1) const
virtual AliVParticle * GetAcceptParticle(Int_t i=-1) const
Short_t fCharge
select particles with charge=fCharge
virtual Bool_t AcceptParticle(const AliVParticle *vp, UInt_t &rejectionReason) const
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)
Short_t fGeneratorIndex
select MC particles with generator index (default = -1 = switch off selection)
AliParticleIterableContainer::iterator accept_begin() const
virtual Bool_t GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle *part, Double_t mass) const
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
const AliParticleIterableContainer accepted() const
int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose)
const Double_t pi
Int_t GetNAcceptedParticles() const
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
virtual AliVParticle * GetNextParticle()