]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliClusterContainer.cxx
Use of AliEmcalParticle with new dev classes
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliClusterContainer.cxx
1 //
2 // Cluster Container
3 //
4 // Author: M. Verweij
5
6 #include <TClonesArray.h>
7
8 #include "AliVEvent.h"
9 #include "AliLog.h"
10
11 #include "AliClusterContainer.h"
12
13 ClassImp(AliClusterContainer)
14
15 //________________________________________________________________________
16 AliClusterContainer::AliClusterContainer():
17   AliEmcalContainer("AliClusterContainer"),
18   fClusPtCut(0.15),
19   fClusTimeCutLow(-10),
20   fClusTimeCutUp(10),
21   fClusterBitMap(0),
22   fMCClusterBitMap(0),
23   fMinMCLabel(0)
24 {
25   // Default constructor.
26
27   fClassName = "AliVCluster";
28 }
29
30 //________________________________________________________________________
31 AliClusterContainer::AliClusterContainer(const char *name):
32   AliEmcalContainer(name),
33   fClusPtCut(0.15),
34   fClusTimeCutLow(-10),
35   fClusTimeCutUp(10),
36   fClusterBitMap(0),
37   fMCClusterBitMap(0),
38   fMinMCLabel(0)
39 {
40   // Standard constructor.
41
42   fClassName = "AliVCluster";
43 }
44
45 //________________________________________________________________________
46 AliVCluster* AliClusterContainer::GetLeadingCluster(const char* opt)
47 {
48   // Get the leading cluster; use e if "e" is contained in opt (otherwise et)
49
50   TString option(opt);
51   option.ToLower();
52
53   Int_t tempID = fCurrentID;
54
55   AliVCluster *clusterMax = GetNextAcceptCluster(0);
56   AliVCluster *cluster = 0;
57
58   if (option.Contains("e")) {
59     while ((cluster = GetNextAcceptCluster())) {
60       if (cluster->E() > clusterMax->E()) clusterMax = cluster;
61     }
62   }
63   else {
64     Double_t et = 0;
65     Double_t etmax = 0;
66     while ((cluster = GetNextAcceptCluster())) {
67       TLorentzVector mom;
68       cluster->GetMomentum(mom,const_cast<Double_t*>(fVertex));
69       et = mom.Et();
70       if (et > etmax) { 
71         clusterMax = cluster;
72         etmax = et;
73       }
74     }
75   }
76
77   fCurrentID = tempID;
78
79   return clusterMax;
80 }
81
82 //________________________________________________________________________
83 AliVCluster* AliClusterContainer::GetCluster(Int_t i) const {
84
85   //Get i^th cluster in array
86
87   if(i<0 || i>fClArray->GetEntriesFast()) return 0;
88   AliVCluster *vp = static_cast<AliVCluster*>(fClArray->At(i));
89   return vp;
90
91 }
92
93 //________________________________________________________________________
94 AliVCluster* AliClusterContainer::GetAcceptCluster(Int_t i) const {
95   //return pointer to cluster if cluster is accepted
96
97   AliVCluster *vc = GetCluster(i);
98   if(!vc) return 0;
99
100   if(AcceptCluster(vc))
101     return vc;
102   else {
103     AliDebug(2,"Cluster not accepted.");
104     return 0;
105   }
106 }
107
108 //________________________________________________________________________
109 AliVCluster* AliClusterContainer::GetNextAcceptCluster(Int_t i) {
110
111   //Get next accepted cluster; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
112
113   if (i>=0) fCurrentID = i;
114
115   const Int_t n = GetNEntries();
116   AliVCluster *c = 0;
117   while (fCurrentID < n && !c) { 
118     c = GetAcceptCluster(fCurrentID);
119     fCurrentID++;
120   }
121
122   return c;
123 }
124
125 //________________________________________________________________________
126 void AliClusterContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
127 {
128   //Get momentum of the i^th cluster in array
129
130   AliVCluster *vc = GetCluster(i);
131   if(vc) vc->GetMomentum(mom,const_cast<Double_t*>(fVertex));
132 }
133
134 //________________________________________________________________________
135 Bool_t AliClusterContainer::AcceptCluster(AliVCluster *clus) const
136 {
137   // Return true if cluster is accepted.
138
139   if (!clus)
140     return kFALSE;
141       
142   if (!clus->IsEMCAL())
143     return kFALSE;
144
145   if (clus->GetLabel() > fMinMCLabel) {
146     if (clus->TestBits(fMCClusterBitMap) != (Int_t)fMCClusterBitMap) {
147       AliDebug(2,"MC Cluster not accepted because of MC bit map.");
148       return kFALSE;
149     }
150   }
151   else {
152     if (clus->TestBits(fClusterBitMap) != (Int_t)fClusterBitMap) {
153       AliDebug(2,"Cluster not accepted because of bit map.");
154       return kFALSE;
155     }
156   }
157
158   if (clus->GetTOF() > fClusTimeCutUp || clus->GetTOF() < fClusTimeCutLow)
159     return kFALSE;
160
161   TLorentzVector nPart;
162   clus->GetMomentum(nPart, const_cast<Double_t*>(fVertex));
163
164   if (nPart.Et() < fClusPtCut)
165     return kFALSE;
166   
167   return kTRUE;
168
169 }
170
171 //________________________________________________________________________
172 void AliClusterContainer::SetClassName(const char *clname)
173 {
174   // Set the class name
175
176   TClass cls(clname);
177   if (cls.InheritsFrom("AliVCluster")) fClassName = clname;
178   else AliError(Form("Unable to set class name %s for a AliClusterContainer, it must inherits from AliVCluster!",clname));
179 }