]>
Commit | Line | Data |
---|---|---|
b9a6a391 | 1 | //$Id$ |
2 | ||
3 | #include <Riostream.h> | |
4 | #include <TROOT.h> | |
5 | #include <TClonesArray.h> | |
6 | #include <TParticle.h> | |
7 | #include <TMath.h> | |
8 | ||
9 | #include "AliTkTowerV2.h" | |
10 | ||
11 | #define Nparticles__ 100 | |
12 | ||
13 | ClassImp(AliTkTowerV2) | |
14 | ||
15 | AliTkTowerV2::AliTkTowerV2() : TObject(), | |
16 | fEta(-999), fPhi(-999), fEt(-999), | |
17 | fNParticles(0),fEtCharged(0), fEtEM(0), | |
18 | fUpdate(kFALSE), fParticles(0) | |
19 | { | |
20 | fParticles = new TClonesArray("TParticle",Nparticles__); | |
21 | } | |
22 | ||
23 | AliTkTowerV2::AliTkTowerV2(const AliTkTowerV2 &t) : TObject(), | |
24 | fEta(-999), fPhi(-999), fEt(-999), | |
25 | fNParticles(0),fEtCharged(0), fEtEM(0), | |
26 | fUpdate(kFALSE), fParticles(0) | |
27 | { | |
28 | fEta = t.getEta(); | |
29 | fPhi = t.getPhi(); | |
30 | fEt = t.getEt(); | |
31 | fEtCharged = 0; | |
32 | fEtEM = 0; | |
33 | fNParticles = t.getNParticles(); | |
34 | if(fNParticles) fUpdate=kTRUE; | |
35 | else fUpdate=kFALSE; | |
36 | TClonesArray *otherParticles = t.getParticleList(); | |
37 | TParticle *particle; | |
38 | fParticles = new TClonesArray("TParticle",Nparticles__); | |
39 | TIterator *iter = otherParticles->MakeIterator(); | |
40 | Int_t i = 0; | |
41 | while ((particle = (TParticle *) iter->Next()) != NULL) { | |
42 | new ((*fParticles)[i]) TParticle(*particle); | |
43 | i++; | |
44 | if(i>fNParticles) | |
45 | cerr << "TKTowerV2: should not happen " << i << " " << fNParticles << endl; | |
46 | } | |
47 | delete iter; | |
48 | } | |
49 | ||
50 | AliTkTowerV2::~AliTkTowerV2() | |
51 | { | |
52 | delete fParticles; | |
53 | } | |
54 | ||
55 | TClonesArray *AliTkTowerV2::getChargedParticleList() const | |
56 | { | |
57 | TClonesArray *chargedParticles = new TClonesArray("TParticle",Nparticles__); | |
58 | Int_t nChargedParticles = 0; | |
59 | TIterator *iter = getParticleList()->MakeIterator(); | |
60 | TParticle *particle = NULL; | |
61 | while ((particle = (TParticle *) iter->Next()) != NULL) { | |
62 | if (isChargedParticle(particle)) { | |
63 | new ((*chargedParticles)[nChargedParticles]) TParticle(*particle); | |
64 | nChargedParticles++; | |
65 | } | |
66 | } | |
67 | delete iter; | |
68 | return chargedParticles; | |
69 | } | |
70 | ||
71 | TClonesArray *AliTkTowerV2::getNeutralParticleList() const | |
72 | { | |
73 | TClonesArray *neutralParticles = new TClonesArray("TParticle",Nparticles__); | |
74 | Int_t nNeutralParticles = 0; | |
75 | TIterator *iter = getParticleList()->MakeIterator(); | |
76 | TParticle *particle = NULL; | |
77 | while ((particle = (TParticle *) iter->Next()) != NULL) { | |
78 | if (!isChargedParticle(particle)) { | |
79 | new ((*neutralParticles)[nNeutralParticles]) TParticle(*particle); | |
80 | nNeutralParticles++; | |
81 | } | |
82 | } | |
83 | delete iter; | |
84 | return neutralParticles; | |
85 | } | |
86 | ||
87 | void AliTkTowerV2::addParticle(const TParticle *particle) | |
88 | { | |
89 | new ((*fParticles)[fNParticles]) TParticle(*particle); | |
90 | fNParticles++; | |
91 | Float_t et_=TMath::Sqrt(particle->Pt()*particle->Pt()); | |
92 | fEt+=et_; | |
93 | fUpdate=kTRUE; | |
94 | } | |
95 | ||
96 | void AliTkTowerV2::setParticleList(TClonesArray *ptr) | |
97 | { | |
98 | delete fParticles; | |
99 | fParticles=ptr; | |
100 | fNParticles=ptr->GetEntries(); | |
101 | fUpdate=kTRUE; | |
102 | } | |
103 | ||
104 | void AliTkTowerV2::update() | |
105 | { | |
106 | if(!fNParticles) return; | |
107 | if(!fUpdate) return; | |
108 | ||
109 | fEtEM=0; | |
110 | fEtCharged=0; | |
111 | ||
112 | TIterator *iter = fParticles->MakeIterator(); | |
113 | TParticle *particle = NULL; | |
114 | while ((particle = (TParticle *) iter->Next()) != NULL) { | |
115 | Float_t et_=TMath::Sqrt(particle->Pt()*particle->Pt()); | |
116 | if (isChargedParticle(particle)) | |
117 | fEtCharged += et_; | |
118 | ||
119 | if (isEMParticle(particle)) | |
120 | fEtEM += et_; | |
121 | } | |
122 | fUpdate=kFALSE; | |
123 | } | |
124 | ||
125 | void AliTkTowerV2::Clear(Option_t *option) | |
126 | { | |
127 | TObject::Clear(option); | |
128 | fParticles->Clear("C"); | |
129 | fEta=-999; | |
130 | fPhi=-999; | |
131 | fEt=-999; | |
132 | fNParticles = 0; | |
133 | fUpdate=kFALSE; | |
134 | fEtCharged = 0; | |
135 | fEtEM = 0; | |
136 | } | |
137 | ||
138 | Bool_t AliTkTowerV2::isChargedParticle(const TParticle *particle) const | |
139 | { | |
140 | Bool_t isCharged = kFALSE; | |
141 | TParticle *part = new TParticle(*particle); | |
142 | TParticlePDG *partPDG = part->GetPDG(0); | |
143 | if (partPDG->Charge() != 0) { | |
144 | isCharged = kTRUE; | |
145 | } | |
146 | delete part; | |
147 | return isCharged; | |
148 | } | |
149 | ||
150 | Bool_t AliTkTowerV2::isEMParticle(const TParticle *particle) const | |
151 | { | |
152 | Bool_t isEM = kFALSE; | |
153 | // define electrons and gammas as EM particles... | |
154 | // not so sure if this is right... | |
155 | if ((particle->GetPdgCode() == 11) || | |
156 | (particle->GetPdgCode() == -11) || | |
157 | (particle->GetPdgCode() == 22)) { | |
158 | isEM = kTRUE; | |
159 | } | |
160 | return isEM; | |
161 | } | |
162 | ||
163 | Int_t AliTkTowerV2::Compare(const TObject *obj) const | |
164 | { | |
165 | Double_t val=((AliTkTowerV2*)obj)->getEt(); | |
166 | ||
167 | if(fEt>val) return -1; //qsort is ascending | |
168 | else if (fEt<val) return 1; | |
169 | else return 0; | |
170 | } |