AliPhysics  b7e5564 (b7e5564)
 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  fChargeCut(kNoChargeCut),
37  fGeneratorIndex(-1)
38 {
39  fBaseClassName = "AliVParticle";
40  SetClassName("AliVParticle");
41 }
42 
48  AliEmcalContainer(name),
49  fMinDistanceTPCSectorEdge(-1),
50  fChargeCut(kNoChargeCut),
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  switch (fChargeCut) {
342  case kCharged:
343  if (vp->Charge() == 0) {
344  rejectionReason |= kChargeCut;
345  return kFALSE;
346  }
347  break;
348 
349  case kNeutral:
350  if (vp->Charge() != 0) {
351  rejectionReason |= kChargeCut;
352  return kFALSE;
353  }
354  break;
355 
356  case kPositiveCharge:
357  if (vp->Charge() <= 0) {
358  rejectionReason |= kChargeCut;
359  return kFALSE;
360  }
361  break;
362 
363  case kNegativeCharge:
364  if (vp->Charge() >= 0) {
365  rejectionReason |= kChargeCut;
366  return kFALSE;
367  }
368  break;
369 
370  default:
371  break;
372  }
373 
374  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
375  rejectionReason |= kMCGeneratorCut;
376  return kFALSE;
377  }
378 
379  return kTRUE;
380 }
381 
393 Bool_t AliParticleContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
394 {
396  const Double_t pi = TMath::Pi();
397  const Double_t kSector = pi/9;
398  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
399  if(phiDist<fMinDistanceTPCSectorEdge) {
400  rejectionReason |= kMinDistanceTPCSectorEdgeCut;
401  return kFALSE;
402  }
403  }
404 
405  return AliEmcalContainer::ApplyKinematicCuts(mom, rejectionReason);
406 }
407 
415 {
416  Int_t nPart = 0;
417  for(int ipart = 0; ipart < this->GetNParticles(); ipart++){
418  UInt_t rejectionReason = 0;
419  if(this->AcceptParticle(ipart, rejectionReason)) nPart++;
420  }
421  return nPart;
422 }
423 
430 {
431  static TString trackString;
432 
433  if (GetMinPt() == 0) {
434  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
435  }
436  else if (GetMinPt() < 1.0) {
437  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
438  }
439  else {
440  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
441  }
442 
443  return trackString.Data();
444 }
445 
452  return AliParticleIterableContainer(this, false);
453 }
454 
461  return AliParticleIterableContainer(this, true);
462 }
463 
470  return AliParticleIterableMomentumContainer(this, false);
471 }
472 
479  return AliParticleIterableMomentumContainer(this, true);
480 }
481 
482 /******************************************
483  * Unit tests *
484  ******************************************/
485 
486 int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose){
487  std::vector<AliVParticle *> reference, variation;
488  AliVParticle *test = NULL;
489  for(int iclust = 0; iclust < cont->GetNParticles(); iclust++){
490  test = cont->GetParticle(iclust);
491  if(!iteratorType){
492  UInt_t rejectionReason = 0;
493  if(!cont->AcceptParticle(test, rejectionReason)) continue;
494  }
495  reference.push_back(test);
496  }
497 
498  if(!iteratorType){
499  // test accept iterator
500  for(auto part : cont->accepted()){
501  variation.push_back(part);
502  }
503  } else {
504  // test all iterator
505  for(auto part : cont->all()){
506  variation.push_back(part);
507  }
508  }
509 
510  if(verbose) {
511  // Printing cluster addresses:
512  if(reference.size() < 30){
513  std::cout << "Paritcles in reference container: " << std::endl;
514  std::cout << "===========================================" << std::endl;
515  for(std::vector<AliVParticle *>::iterator refit = reference.begin(); refit != reference.end(); ++refit){
516  std::cout << "Address: " << *refit << std::endl;
517  }
518  }
519  if(variation.size() < 30){
520  std::cout << "Paritcles in test container: " << std::endl;
521  std::cout << "===========================================" << std::endl;
522  for(std::vector<AliVParticle *>::iterator varit = variation.begin(); varit != variation.end(); ++varit){
523  std::cout << "Address: " << *varit << std::endl;
524  }
525  }
526  }
527 
528  int testresult = 0;
529  // compare distributions: all particles in one vector needs to be found in the other vector and vice versa
530  bool failure = false;
531  // first test: cleck if all particles are found by the iterator
532  for(std::vector<AliVParticle *>::iterator clit = reference.begin(); clit != reference.end(); ++clit){
533  if(std::find(variation.begin(), variation.end(), *clit) == variation.end()) {
534  if(verbose)
535  std::cout << "Could not find particle with address " << *clit << " in test container" << std::endl;
536  failure = true;
537  break;
538  }
539  }
540  if(!failure){
541  // second test: check if there are no extra particles found
542  for(std::vector<AliVParticle *>::iterator clit = variation.begin(); clit != variation.end(); ++clit){
543  if(std::find(reference.begin(), reference.end(), *clit) == reference.end()) {
544  if(verbose)
545  std::cout << "Could not find particle with address " << *clit << " in reference container" << std::endl;
546  failure = true;
547  break;
548  }
549  }
550  if(failure) testresult = 2;
551  } else testresult = 1;
552  if(verbose) {
553  std::cout << "Unit test particle container, iterator type " << iteratorType << std::endl;
554  std::cout << "Number of expected particles: " << reference.size() << ", number of found particles: " << variation.size() << std::endl;
555  std::cout << "Test result: " << testresult << std::endl;
556  std::cout << "-----------------------------------------------------------------------" << std::endl;
557  }
558  return testresult;
559 }
const Double_t kSector
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
Declaration of class AliTLorentzVector.
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp, UInt_t &rejectionReason) const
EChargeCut_t fChargeCut
select particles according to their charge
virtual Bool_t GetNextMomentum(TLorentzVector &mom)
Container for particles within the EMCAL framework.
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom)
virtual AliVParticle * GetLeadingParticle(const char *opt="")
virtual AliVParticle * GetParticle(Int_t i=-1) const
EMCALIterableContainer::AliEmcalIterableContainerT< AliVParticle, EMCALIterableContainer::operator_star_object< AliVParticle > > AliParticleIterableContainer
virtual AliVParticle * GetAcceptParticle(Int_t i=-1) const
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)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
virtual Bool_t GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle *part, Double_t mass) const
const AliParticleIterableMomentumContainer accepted_momentum() 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)
EMCALIterableContainer::AliEmcalIterableContainerT< AliVParticle, EMCALIterableContainer::operator_star_pair< AliVParticle > > AliParticleIterableMomentumContainer
const Double_t pi
Int_t GetNAcceptedParticles() const
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
const AliParticleIterableMomentumContainer all_momentum() const
virtual AliVParticle * GetNextParticle()