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