AliPhysics  de71be2 (de71be2)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AliClusterContainer.cxx
Go to the documentation of this file.
1 //
2 // Container with name, TClonesArray and cuts for calo clusters
3 //
4 // Author: M. Verweij, S. Aiola
5 
6 #include <TClonesArray.h>
7 
8 #include "AliVEvent.h"
9 #include "AliLog.h"
10 #include "AliTLorentzVector.h"
11 
12 #include "AliClusterContainer.h"
13 
15 
16 //________________________________________________________________________
19  fClusTimeCutLow(-10),
20  fClusTimeCutUp(10),
21  fExoticCut(kTRUE),
22  fDefaultClusterEnergy(-1)
23 {
24  // Default constructor.
25 
26  fClassName = "AliVCluster";
27 
28  for (Int_t i = 0; i <= AliVCluster::kLastUserDefEnergy; i++) {
29  fUserDefEnergyCut[i] = 0.;
30  }
31 }
32 
33 //________________________________________________________________________
35  AliEmcalContainer(name),
36  fClusTimeCutLow(-10),
37  fClusTimeCutUp(10),
38  fExoticCut(kTRUE),
39  fDefaultClusterEnergy(-1)
40 {
41  // Standard constructor.
42 
43  fClassName = "AliVCluster";
44 
45  for (Int_t i = 0; i <= AliVCluster::kLastUserDefEnergy; i++) {
46  fUserDefEnergyCut[i] = 0.;
47  }
48 }
49 
50 //________________________________________________________________________
51 AliVCluster* AliClusterContainer::GetLeadingCluster(const char* opt)
52 {
53  // Get the leading cluster; use e if "e" is contained in opt (otherwise et)
54 
55  TString option(opt);
56  option.ToLower();
57 
58  Int_t tempID = fCurrentID;
59 
60  AliVCluster *clusterMax = GetNextAcceptCluster(0);
61  AliVCluster *cluster = 0;
62 
63  if (option.Contains("e")) {
64  while ((cluster = GetNextAcceptCluster())) {
65  if (cluster->E() > clusterMax->E()) clusterMax = cluster;
66  }
67  }
68  else {
69  Double_t et = 0;
70  Double_t etmax = 0;
71  while ((cluster = GetNextAcceptCluster())) {
72  TLorentzVector mom;
73  cluster->GetMomentum(mom,const_cast<Double_t*>(fVertex));
74  et = mom.Et();
75  if (et > etmax) {
76  clusterMax = cluster;
77  etmax = et;
78  }
79  }
80  }
81 
82  fCurrentID = tempID;
83 
84  return clusterMax;
85 }
86 
87 //________________________________________________________________________
88 AliVCluster* AliClusterContainer::GetCluster(Int_t i) const
89 {
90  //Get i^th cluster in array
91 
92  if(i<0 || i>fClArray->GetEntriesFast()) return 0;
93  AliVCluster *vp = static_cast<AliVCluster*>(fClArray->At(i));
94  return vp;
95 
96 }
97 
98 //________________________________________________________________________
100 {
101  //Return pointer to cluster if cluster is accepted
102 
103  AliVCluster *vc = GetCluster(i);
104  if (!vc) return 0;
105 
106  if (AcceptCluster(vc))
107  return vc;
108  else {
109  AliDebug(2,"Cluster not accepted.");
110  return 0;
111  }
112 }
113 
114 //________________________________________________________________________
115 AliVCluster* AliClusterContainer::GetClusterWithLabel(Int_t lab) const
116 {
117  //Get particle with label lab in array
118 
119  Int_t i = GetIndexFromLabel(lab);
120  return GetCluster(i);
121 }
122 
123 //________________________________________________________________________
125 {
126  //Get particle with label lab in array
127 
128  Int_t i = GetIndexFromLabel(lab);
129  return GetAcceptCluster(i);
130 }
131 
132 //________________________________________________________________________
134 {
135  //Get next accepted cluster; if i >= 0 (re)start counter from i; return 0 if no accepted cluster could be found
136 
137  if (i>=0) fCurrentID = i;
138 
139  const Int_t n = GetNEntries();
140  AliVCluster *c = 0;
141  do {
142  fCurrentID++;
143  if (fCurrentID >= n) break;
145  } while (!c);
146 
147  return c;
148 }
149 
150 //________________________________________________________________________
152 {
153  //Get next cluster; if i >= 0 (re)start counter from i; return 0 if no cluster could be found
154 
155  if (i>=0) fCurrentID = i;
156 
157  const Int_t n = GetNEntries();
158  AliVCluster *c = 0;
159  do {
160  fCurrentID++;
161  if (fCurrentID >= n) break;
162  c = GetCluster(fCurrentID);
163  } while (!c);
164 
165  return c;
166 }
167 
168 //________________________________________________________________________
169 Bool_t AliClusterContainer::GetMomentum(TLorentzVector &mom, const AliVCluster* vc, Double_t mass)
170 {
171  if (mass < 0) mass = 0;
172 
173  Double_t energy = 0;
174 
175  if (fDefaultClusterEnergy >= 0 && fDefaultClusterEnergy <= AliVCluster::kLastUserDefEnergy) {
176  energy = vc->GetUserDefEnergy((AliVCluster::VCluUserDefEnergy_t)fDefaultClusterEnergy);
177  }
178  else {
179  energy = vc->E();
180  }
181 
182  Double_t p = TMath::Sqrt(energy*energy - mass*mass);
183 
184  Float_t pos[3];
185  vc->GetPosition(pos);
186 
187  pos[0]-=fVertex[0];
188  pos[1]-=fVertex[1];
189  pos[2]-=fVertex[2];
190 
191  Double_t r = TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]) ;
192 
193  if (r > 1e-12) {
194  mom.SetPxPyPzE( p*pos[0]/r, p*pos[1]/r, p*pos[2]/r, energy) ;
195  }
196  else {
197  AliInfo("Null cluster radius, momentum calculation not possible");
198  return kFALSE;
199  }
200 
201  return kTRUE;
202 }
203 
204 //________________________________________________________________________
205 Bool_t AliClusterContainer::GetMomentum(TLorentzVector &mom, const AliVCluster* vc)
206 {
207  if (fMassHypothesis > 0) return GetMomentum(mom, vc, fMassHypothesis);
208 
209  if (vc) {
210  if (fDefaultClusterEnergy >= 0 && fDefaultClusterEnergy <= AliVCluster::kLastUserDefEnergy) {
211  vc->GetMomentum(mom, fVertex, (AliVCluster::VCluUserDefEnergy_t)fDefaultClusterEnergy);
212  }
213  else {
214  vc->GetMomentum(mom, fVertex);
215  }
216  }
217  else {
218  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
219  return kFALSE;
220  }
221  return kTRUE;
222 }
223 
224 //________________________________________________________________________
225 Bool_t AliClusterContainer::GetMomentum(TLorentzVector &mom, Int_t i)
226 {
227  //Get momentum of the i^th particle in array
228 
229  AliVCluster *vc = GetCluster(i);
230  return GetMomentum(mom, vc);
231 }
232 
233 //________________________________________________________________________
234 Bool_t AliClusterContainer::GetNextMomentum(TLorentzVector &mom, Int_t i)
235 {
236  //Get momentum of the i^th particle in array
237 
238  AliVCluster *vc = GetNextCluster(i);
239  return GetMomentum(mom, vc);
240 }
241 
242 //________________________________________________________________________
243 Bool_t AliClusterContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
244 {
245  //Get momentum of the i^th particle in array
246 
247  AliVCluster *vc = GetAcceptCluster(i);
248  return GetMomentum(mom, vc);
249 }
250 
251 //________________________________________________________________________
252 Bool_t AliClusterContainer::GetNextAcceptMomentum(TLorentzVector &mom, Int_t i)
253 {
254  //Get momentum of the i^th particle in array
255 
256  AliVCluster *vc = GetNextAcceptCluster(i);
257  return GetMomentum(mom, vc);
258 }
259 
260 //________________________________________________________________________
262 {
263  Bool_t r = ApplyClusterCuts(GetCluster(i));
264  if (!r) return kFALSE;
265 
266  AliTLorentzVector mom;
267  GetMomentum(mom, i);
268 
269  return ApplyKinematicCuts(mom);
270 }
271 
272 //________________________________________________________________________
273 Bool_t AliClusterContainer::AcceptCluster(const AliVCluster* clus)
274 {
275  Bool_t r = ApplyClusterCuts(clus);
276  if (!r) return kFALSE;
277 
278  AliTLorentzVector mom;
279  GetMomentum(mom, clus);
280 
281  return ApplyKinematicCuts(mom);
282 }
283 
284 //________________________________________________________________________
285 Bool_t AliClusterContainer::ApplyClusterCuts(const AliVCluster* clus)
286 {
287  // Return true if cluster is accepted.
288 
289  fRejectionReason = 0;
290 
291  if (!clus) {
293  return kFALSE;
294  }
295 
296  if (!clus->IsEMCAL()) {
298  return kFALSE;
299  }
300 
301  if (clus->TestBits(fBitMap) != (Int_t)fBitMap) {
303  return kFALSE;
304  }
305 
306  if (fMinMCLabel >= 0 && TMath::Abs(clus->GetLabel()) > fMinMCLabel) {
308  return kFALSE;
309  }
310 
311  if (fMaxMCLabel >= 0 && TMath::Abs(clus->GetLabel()) < fMaxMCLabel) {
313  return kFALSE;
314  }
315 
316  if (clus->GetTOF() > fClusTimeCutUp || clus->GetTOF() < fClusTimeCutLow) {
318  return kFALSE;
319  }
320 
321  if (fExoticCut && clus->GetIsExotic()) {
323  return kFALSE;
324  }
325 
326  for (Int_t i = 0; i <= AliVCluster::kLastUserDefEnergy; i++) {
327  if (clus->GetUserDefEnergy((VCluUserDefEnergy_t)i) < fUserDefEnergyCut[i]) {
329  return kFALSE;
330  }
331  }
332 
333  return kTRUE;
334 }
335 
336 //________________________________________________________________________
338 {
339  // Get number of accepted particles
340 
341  Int_t nClus = 0;
342 
343  AliVCluster *clus = GetNextAcceptCluster(0);
344  if(clus) nClus = 1;
345  while (GetNextAcceptCluster())
346  nClus++;
347 
348  return nClus;
349 }
350 
351 //________________________________________________________________________
353 {
354  if (t >= 0 && t <= AliVCluster::kLastUserDefEnergy){
355  return fUserDefEnergyCut[t];
356  }
357  else {
358  return fMinE;
359  }
360 }
361 
362 //________________________________________________________________________
364 {
365  if (t >= 0 && t <= AliVCluster::kLastUserDefEnergy){
366  fUserDefEnergyCut[t] = cut;
367  }
368  else {
369  fMinE = cut;
370  }
371 }
372 
373 
374 //________________________________________________________________________
375 void AliClusterContainer::SetClassName(const char *clname)
376 {
377  // Set the class name
378 
379  TClass cls(clname);
380  if (cls.InheritsFrom("AliVCluster")) fClassName = clname;
381  else AliError(Form("Unable to set class name %s for a AliClusterContainer, it must inherits from AliVCluster!",clname));
382 }
383 
384 //________________________________________________________________________
385 const char* AliClusterContainer::GetTitle() const
386 {
387  static TString clusterString;
388 
390 
391  if (Ecut == 0) {
392  clusterString = TString::Format("%s_E0000", GetArrayName().Data());
393  }
394  else if (Ecut < 1.0) {
395  clusterString = TString::Format("%s_E0%3.0f", GetArrayName().Data(), Ecut*1000.0);
396  }
397  else {
398  clusterString = TString::Format("%s_E%4.0f", GetArrayName().Data(), Ecut*1000.0);
399  }
400 
401  return clusterString.Data();
402 }
const char * GetTitle() const
Int_t GetIndexFromLabel(Int_t lab) const
AliVCluster * GetAcceptClusterWithLabel(Int_t lab)
Double_t mass
Double_t fUserDefEnergyCut[AliVCluster::kLastUserDefEnergy+1]
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
AliVCluster * GetNextAcceptCluster(Int_t i=-1)
void SetClusUserDefEnergyCut(Int_t t, Double_t cut)
AliVCluster * GetLeadingCluster(const char *opt="")
Double_t GetClusUserDefEnergyCut(Int_t t) const
Int_t GetDefaultClusterEnergy() const
Bool_t GetNextAcceptMomentum(TLorentzVector &mom, Int_t i=-1)
enum AliVCluster::VCluUserDefEnergy_t VCluUserDefEnergy_t
UInt_t fRejectionReason
event vertex array
AliVCluster * GetAcceptCluster(Int_t i)
Bool_t GetNextMomentum(TLorentzVector &mom, Int_t i=-1)
AliVCluster * GetNextCluster(Int_t i=-1)
ClassImp(AliClusterContainer) AliClusterContainer
virtual Bool_t ApplyClusterCuts(const AliVCluster *clus)
AliVCluster * GetCluster(Int_t i) const
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)
void SetClassName(const char *clname)
energy
Bool_t GetMomentum(TLorentzVector &mom, const AliVCluster *vc, Double_t mass)
const TString & GetArrayName() const
Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i)
Double_t fVertex[3]
Label-Index map.
AliVCluster * GetClusterWithLabel(Int_t lab) const
virtual Bool_t AcceptCluster(Int_t i)
TClonesArray * fClArray
Int_t GetNEntries() const
Int_t fCurrentID
TClonesArray.