AliPhysics  a9863a5 (a9863a5)
 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 
418 /******************************************
419  * Unit tests *
420  ******************************************/
421 
422 int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose){
423  std::vector<AliVParticle *> reference, variation;
424  AliVParticle *test = NULL;
425  for(int iclust = 0; iclust < cont->GetNParticles(); iclust++){
426  test = cont->GetParticle(iclust);
427  if(!iteratorType){
428  UInt_t rejectionReason = 0;
429  if(!cont->AcceptParticle(test, rejectionReason)) continue;
430  }
431  reference.push_back(test);
432  }
433 
434  if(!iteratorType){
435  // test accept iterator
436  for(AliParticleIterableContainer::iterator iter = cont->accept_begin(); iter != cont->accept_end(); ++iter){
437  variation.push_back(*iter);
438  }
439  } else {
440  // test all iterator
441  for(AliParticleIterableContainer::iterator iter = cont->begin(); iter != cont->end(); ++iter){
442  variation.push_back(*iter);
443  }
444  }
445 
446  if(verbose) {
447  // Printing cluster addresses:
448  if(reference.size() < 30){
449  std::cout << "Paritcles in reference container: " << std::endl;
450  std::cout << "===========================================" << std::endl;
451  for(std::vector<AliVParticle *>::iterator refit = reference.begin(); refit != reference.end(); ++refit){
452  std::cout << "Address: " << *refit << std::endl;
453  }
454  }
455  if(variation.size() < 30){
456  std::cout << "Paritcles in test container: " << std::endl;
457  std::cout << "===========================================" << std::endl;
458  for(std::vector<AliVParticle *>::iterator varit = variation.begin(); varit != variation.end(); ++varit){
459  std::cout << "Address: " << *varit << std::endl;
460  }
461  }
462  }
463 
464  int testresult = 0;
465  // compare distributions: all particles in one vector needs to be found in the other vector and vice versa
466  bool failure = false;
467  // first test: cleck if all particles are found by the iterator
468  for(std::vector<AliVParticle *>::iterator clit = reference.begin(); clit != reference.end(); ++clit){
469  if(std::find(variation.begin(), variation.end(), *clit) == variation.end()) {
470  if(verbose)
471  std::cout << "Could not find particle with address " << *clit << " in test container" << std::endl;
472  failure = true;
473  break;
474  }
475  }
476  if(!failure){
477  // second test: check if there are no extra particles found
478  for(std::vector<AliVParticle *>::iterator clit = variation.begin(); clit != variation.end(); ++clit){
479  if(std::find(reference.begin(), reference.end(), *clit) == reference.end()) {
480  if(verbose)
481  std::cout << "Could not find particle with address " << *clit << " in reference container" << std::endl;
482  failure = true;
483  break;
484  }
485  }
486  if(failure) testresult = 2;
487  } else testresult = 1;
488  if(verbose) {
489  std::cout << "Unit test particle container, iterator type " << iteratorType << std::endl;
490  std::cout << "Number of expected particles: " << reference.size() << ", number of found particles: " << variation.size() << std::endl;
491  std::cout << "Test result: " << testresult << std::endl;
492  std::cout << "-----------------------------------------------------------------------" << std::endl;
493  }
494  return testresult;
495 }
const Double_t kSector
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
virtual AliVParticle * GetNextAcceptParticle()
virtual Bool_t GetMomentum(TLorentzVector &mom, Int_t i) const
const char * GetTitle() const
Double_t mass
Int_t GetNParticles() const
UInt_t fBitMap
bitmap mask
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp, UInt_t &rejectionReason) const
Track too close to the TPC sector boundary.
AliParticleIterableContainer::iterator accept_end() const
AliParticleIterableContainer::iterator begin() const
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
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.
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
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)
AliParticleIterableContainer::iterator accept_begin() 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
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
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
void ResetCurrentID(Int_t i=-1)
virtual AliVParticle * GetNextParticle()