AliPhysics  ff07904 (ff07904)
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 
27 ClassImp(AliParticleContainer);
29 
30 // Properly instantiate the object
32 
37  AliEmcalContainer(),
38  fMinDistanceTPCSectorEdge(-1),
39  fChargeCut(kNoChargeCut),
40  fGeneratorIndex(-1)
41 {
42  fBaseClassName = "AliVParticle";
43  SetClassName("AliVParticle");
44 }
45 
51  AliEmcalContainer(name),
54  fGeneratorIndex(-1)
55 {
56  fBaseClassName = "AliVParticle";
57  SetClassName("AliVParticle");
58 }
59 
66 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
67 {
68  TString option(opt);
69  option.ToLower();
70 
71  Int_t tempID = fCurrentID;
72  ResetCurrentID();
73 
74  AliVParticle *partMax = GetNextAcceptParticle();
75  AliVParticle *part = 0;
76 
77  if (option.Contains("p")) {
78  while ((part = GetNextAcceptParticle())) {
79  if (part->P() > partMax->P()) partMax = part;
80  }
81  }
82  else {
83  while ((part = GetNextAcceptParticle())) {
84  if (part->Pt() > partMax->Pt()) partMax = part;
85  }
86  }
87 
88  fCurrentID = tempID;
89 
90  return partMax;
91 }
92 
99 {
100  //
101  if (i == -1) i = fCurrentID;
102  if (i < 0 || i >= this->fClArray->GetEntriesFast()) return 0;
103  AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
104  return vp;
105 }
106 
114 {
115  UInt_t rejectionReason = 0;
116  if (i == -1) i = fCurrentID;
117  if (AcceptParticle(i, rejectionReason)) {
118  return GetParticle(i);
119  }
120  else {
121  AliDebug(2,"Particle not accepted.");
122  return 0;
123  }
124 }
125 
133 {
134  const Int_t n = GetNEntries();
135  AliVParticle *p = 0;
136  do {
137  fCurrentID++;
138  if (fCurrentID >= n) break;
139  p = GetAcceptParticle(fCurrentID);
140  } while (!p);
141 
142  return p;
143 }
144 
152 {
153  const Int_t n = GetNEntries();
154  AliVParticle *p = 0;
155  do {
156  fCurrentID++;
157  if (fCurrentID >= n) break;
158  p = GetParticle(fCurrentID);
159  } while (!p);
160 
161  return p;
162 }
163 
173 Bool_t AliParticleContainer::GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle* part, Double_t mass) const
174 {
175  if (part && part->Eta() < 1e6 && part->Eta() > -1e6) { // protection against FPE in sinh(eta)
176  if (mass < 0) mass = part->M();
177  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
178  return kTRUE;
179  }
180  else {
181  mom.SetPtEtaPhiM(0, 0, 0, 0);
182  return kFALSE;
183  }
184 }
185 
193 Bool_t AliParticleContainer::GetMomentumFromParticle(TLorentzVector &mom, const AliVParticle* part) const
194 {
195  return GetMomentumFromParticle(mom,part,fMassHypothesis);
196 }
197 
207 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
208 {
209  if (i == -1) i = fCurrentID;
210  AliVParticle *vp = GetParticle(i);
211  return GetMomentumFromParticle(mom, vp);
212 }
213 
224 {
225  AliVParticle *vp = GetNextParticle();
226  return GetMomentumFromParticle(mom, vp);
227 }
228 
240 {
241  if (i == -1) i = fCurrentID;
242  AliVParticle *vp = GetAcceptParticle(i);
243  return GetMomentumFromParticle(mom, vp);
244 }
245 
256 {
257  AliVParticle *vp = GetNextAcceptParticle();
258  return GetMomentumFromParticle(mom, vp);
259 }
260 
271 Bool_t AliParticleContainer::AcceptParticle(const AliVParticle *vp, UInt_t &rejectionReason) const
272 {
273  Bool_t r = ApplyParticleCuts(vp, rejectionReason);
274  if (!r) return kFALSE;
275 
276  AliTLorentzVector mom;
277 
278  Int_t id = fClArray->IndexOf(vp);
279  bool status(true);
280  if (id >= 0) {
281  status = GetMomentum(mom, id);
282  }
283  else {
284  status = GetMomentumFromParticle(mom, vp);
285  }
286  if(!status) return false;
287 
288  return ApplyKinematicCuts(mom, rejectionReason);
289 }
290 
302 {
303  Bool_t r = ApplyParticleCuts(GetParticle(i), rejectionReason);
304  if (!r) return kFALSE;
305 
306  AliTLorentzVector mom;
307  if(!GetMomentum(mom, i)) return false;
308 
309  return ApplyKinematicCuts(mom, rejectionReason);
310 }
311 
324 Bool_t AliParticleContainer::ApplyParticleCuts(const AliVParticle* vp, UInt_t &rejectionReason) const
325 {
326  if (!vp) {
327  rejectionReason |= kNullObject;
328  return kFALSE;
329  }
330 
331  if (vp->TestBits(fBitMap) != (Int_t)fBitMap) {
332  rejectionReason |= kBitMapCut;
333  return kFALSE;
334  }
335 
336  if (fMinMCLabel >= 0 && TMath::Abs(vp->GetLabel()) < fMinMCLabel) {
337  rejectionReason |= kMCLabelCut;
338  return kFALSE;
339  }
340 
341  if (fMaxMCLabel >= 0 && TMath::Abs(vp->GetLabel()) > fMaxMCLabel) {
342  rejectionReason |= kMCLabelCut;
343  return kFALSE;
344  }
345 
346  switch (fChargeCut) {
347  case kCharged:
348  if (vp->Charge() == 0) {
349  rejectionReason |= kChargeCut;
350  return kFALSE;
351  }
352  break;
353 
354  case kNeutral:
355  if (vp->Charge() != 0) {
356  rejectionReason |= kChargeCut;
357  return kFALSE;
358  }
359  break;
360 
361  case kPositiveCharge:
362  if (vp->Charge() <= 0) {
363  rejectionReason |= kChargeCut;
364  return kFALSE;
365  }
366  break;
367 
368  case kNegativeCharge:
369  if (vp->Charge() >= 0) {
370  rejectionReason |= kChargeCut;
371  return kFALSE;
372  }
373  break;
374 
375  default:
376  break;
377  }
378 
379  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
380  rejectionReason |= kMCGeneratorCut;
381  return kFALSE;
382  }
383 
384  return kTRUE;
385 }
386 
399 {
401  const Double_t pi = TMath::Pi();
402  const Double_t kSector = pi/9;
403  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
404  if(phiDist<fMinDistanceTPCSectorEdge) {
405  rejectionReason |= kMinDistanceTPCSectorEdgeCut;
406  return kFALSE;
407  }
408  }
409 
410  return AliEmcalContainer::ApplyKinematicCuts(mom, rejectionReason);
411 }
412 
420 {
421  Int_t nPart = 0;
422  for(int ipart = 0; ipart < this->GetNParticles(); ipart++){
423  UInt_t rejectionReason = 0;
424  if(this->AcceptParticle(ipart, rejectionReason)) nPart++;
425  }
426  return nPart;
427 }
428 
435 {
436  static TString trackString;
437  trackString = TString::Format("%s_pT%04d", GetArrayName().Data(), static_cast<int>(GetMinPt()*1000.0));
438  return trackString.Data();
439 }
440 
449 void AliParticleContainer::SetArray(const AliVEvent * event)
450 {
451  AliEmcalContainer::SetArray(event);
452 
453  // Register TClonesArray in index map
455 }
456 
463  return AliParticleIterableContainer(this, false);
464 }
465 
472  return AliParticleIterableContainer(this, true);
473 }
474 
481  return AliParticleIterableMomentumContainer(this, false);
482 }
483 
490  return AliParticleIterableMomentumContainer(this, true);
491 }
492 
493 /******************************************
494  * Unit tests *
495  ******************************************/
496 
497 int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose){
498  std::vector<AliVParticle *> reference, variation;
499  AliVParticle *test = NULL;
500  for(int iclust = 0; iclust < cont->GetNParticles(); iclust++){
501  test = cont->GetParticle(iclust);
502  if(!iteratorType){
503  UInt_t rejectionReason = 0;
504  if(!cont->AcceptParticle(test, rejectionReason)) continue;
505  }
506  reference.push_back(test);
507  }
508 
509  if(!iteratorType){
510  // test accept iterator
511  for(auto part : cont->accepted()){
512  variation.push_back(part);
513  }
514  } else {
515  // test all iterator
516  for(auto part : cont->all()){
517  variation.push_back(part);
518  }
519  }
520 
521  if(verbose) {
522  // Printing cluster addresses:
523  if(reference.size() < 30){
524  std::cout << "Paritcles in reference container: " << std::endl;
525  std::cout << "===========================================" << std::endl;
526  for(std::vector<AliVParticle *>::iterator refit = reference.begin(); refit != reference.end(); ++refit){
527  std::cout << "Address: " << *refit << std::endl;
528  }
529  }
530  if(variation.size() < 30){
531  std::cout << "Paritcles in test container: " << std::endl;
532  std::cout << "===========================================" << std::endl;
533  for(std::vector<AliVParticle *>::iterator varit = variation.begin(); varit != variation.end(); ++varit){
534  std::cout << "Address: " << *varit << std::endl;
535  }
536  }
537  }
538 
539  int testresult = 0;
540  // compare distributions: all particles in one vector needs to be found in the other vector and vice versa
541  bool failure = false;
542  // first test: cleck if all particles are found by the iterator
543  for(std::vector<AliVParticle *>::iterator clit = reference.begin(); clit != reference.end(); ++clit){
544  if(std::find(variation.begin(), variation.end(), *clit) == variation.end()) {
545  if(verbose)
546  std::cout << "Could not find particle with address " << *clit << " in test container" << std::endl;
547  failure = true;
548  break;
549  }
550  }
551  if(!failure){
552  // second test: check if there are no extra particles found
553  for(std::vector<AliVParticle *>::iterator clit = variation.begin(); clit != variation.end(); ++clit){
554  if(std::find(reference.begin(), reference.end(), *clit) == reference.end()) {
555  if(verbose)
556  std::cout << "Could not find particle with address " << *clit << " in reference container" << std::endl;
557  failure = true;
558  break;
559  }
560  }
561  if(failure) testresult = 2;
562  } else testresult = 1;
563  if(verbose) {
564  std::cout << "Unit test particle container, iterator type " << iteratorType << std::endl;
565  std::cout << "Number of expected particles: " << reference.size() << ", number of found particles: " << variation.size() << std::endl;
566  std::cout << "Test result: " << testresult << std::endl;
567  std::cout << "-----------------------------------------------------------------------" << std::endl;
568  }
569  return testresult;
570 }
const Double_t kSector
virtual AliVParticle * GetNextAcceptParticle()
double Double_t
Definition: External.C:58
void SetArray(const AliVEvent *event)
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)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
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
static AliEmcalContainerIndexMap< TClonesArray, AliVParticle > fgEmcalContainerIndexMap
! Mapping from containers to indices
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)
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
void test(int runnumber=195345)
int TestParticleContainerIterator(const AliParticleContainer *const cont, int iteratorType, bool verbose)
EMCALIterableContainer::AliEmcalIterableContainerT< AliVParticle, EMCALIterableContainer::operator_star_pair< AliVParticle > > AliParticleIterableMomentumContainer
const Double_t pi
bool Bool_t
Definition: External.C:53
Int_t GetNAcceptedParticles() const
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
const AliParticleIterableMomentumContainer all_momentum() const
virtual AliVParticle * GetNextParticle()