]>
Commit | Line | Data |
---|---|---|
8afc7c8d | 1 | // $Id: AliJetConstituentTagCopier.cxx $ |
2 | // | |
3 | // Copy tags from particle level constituent to detector level | |
4 | // | |
5 | // Author: S. Aiola | |
6 | ||
7 | #include "AliJetConstituentTagCopier.h" | |
8 | ||
9 | #include <TClonesArray.h> | |
5ce8ae64 | 10 | #include <TMath.h> |
8afc7c8d | 11 | |
5be3857d | 12 | #include "AliNamedArrayI.h" |
8afc7c8d | 13 | #include "AliVCluster.h" |
14 | #include "AliVParticle.h" | |
15 | #include "AliEmcalParticle.h" | |
16 | #include "AliLog.h" | |
17 | ||
18 | ClassImp(AliJetConstituentTagCopier) | |
19 | ||
20 | //________________________________________________________________________ | |
21 | AliJetConstituentTagCopier::AliJetConstituentTagCopier() : | |
22 | AliAnalysisTaskEmcal("AliJetConstituentTagCopier", kFALSE), | |
23 | fMCParticlesName(), | |
24 | fMCParticles(0), | |
25 | fMCParticlesMap(0) | |
26 | { | |
27 | // Default constructor. | |
28 | } | |
29 | ||
30 | //________________________________________________________________________ | |
31 | AliJetConstituentTagCopier::AliJetConstituentTagCopier(const char *name) : | |
32 | AliAnalysisTaskEmcal(name, kFALSE), | |
33 | fMCParticlesName("MCParticles"), | |
34 | fMCParticles(0), | |
35 | fMCParticlesMap(0) | |
36 | { | |
37 | // Standard constructor. | |
38 | } | |
39 | ||
40 | //________________________________________________________________________ | |
41 | AliJetConstituentTagCopier::~AliJetConstituentTagCopier() | |
42 | { | |
43 | // Destructor | |
44 | } | |
45 | ||
46 | //________________________________________________________________________ | |
47 | void AliJetConstituentTagCopier::ExecOnce() | |
48 | { | |
49 | // Execute once. | |
50 | ||
51 | if (!fMCParticles) { | |
52 | fMCParticles = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fMCParticlesName)); | |
53 | if (!fMCParticles) { | |
54 | AliError(Form("%s: Could not retrieve MC particles %s!", GetName(), fMCParticlesName.Data())); | |
55 | return; | |
56 | } | |
57 | else if (!fMCParticles->GetClass()->GetBaseClass("AliVParticle")) { | |
58 | AliError(Form("%s: Collection %s does not contain AliVParticle objects!", GetName(), fMCParticlesName.Data())); | |
59 | fMCParticles = 0; | |
60 | return; | |
61 | } | |
62 | } | |
63 | ||
64 | if (!fMCParticlesMap) { | |
5be3857d | 65 | fMCParticlesMap = dynamic_cast<AliNamedArrayI*>(InputEvent()->FindListObject(fMCParticlesName + "_Map")); |
8afc7c8d | 66 | // this is needed to map the MC labels with the indexes of the MC particle collection |
67 | // if teh map is not given, the MC labels are assumed to be consistent with the indexes (which is not the case if AliEmcalMCTrackSelector is used) | |
68 | if (!fMCParticlesMap) { | |
69 | AliWarning(Form("%s: Could not retrieve map for MC particles %s! Will assume MC labels consistent with indexes...", GetName(), fMCParticlesName.Data())); | |
5be3857d | 70 | fMCParticlesMap = new AliNamedArrayI("tracksMap",9999); |
8afc7c8d | 71 | for (Int_t i = 0; i < 9999; i++) { |
5be3857d | 72 | fMCParticlesMap->AddAt(i,i); |
8afc7c8d | 73 | } |
74 | } | |
75 | } | |
76 | ||
77 | AliAnalysisTaskEmcal::ExecOnce(); | |
78 | } | |
79 | ||
80 | //________________________________________________________________________ | |
81 | Bool_t AliJetConstituentTagCopier::Run() | |
82 | { | |
83 | if (fTracks) { | |
84 | if (fTracks->GetClass()->GetBaseClass("AliVParticle")) | |
85 | DoTrackLoop(fTracks); | |
86 | else if (fTracks->GetClass()->GetBaseClass("AliEmcalParticle")) | |
87 | DoEmcalParticleLoop(fTracks); | |
88 | else | |
89 | AliError(Form("%s: Object type not recognized in collection %s. Nothing will be done.", GetName(), fTracks->GetName())); | |
90 | } | |
91 | ||
92 | if (fCaloClusters) { | |
93 | if (fCaloClusters->GetClass()->GetBaseClass("AliVCluster")) | |
94 | DoClusterLoop(fCaloClusters); | |
95 | else if (fCaloClusters->GetClass()->GetBaseClass("AliEmcalParticle")) | |
96 | DoEmcalParticleLoop(fCaloClusters); | |
97 | else | |
98 | AliError(Form("%s: Object type not recognized in collection %s. Nothing will be done.", GetName(), fCaloClusters->GetName())); | |
99 | } | |
100 | ||
101 | return kTRUE; | |
102 | } | |
103 | ||
104 | //________________________________________________________________________ | |
105 | void AliJetConstituentTagCopier::DoClusterLoop(TClonesArray *array) | |
106 | { | |
107 | for (Int_t i = 0; i < array->GetEntries(); i++) { | |
108 | AliVCluster *cluster = static_cast<AliVCluster*>(array->At(i)); | |
109 | if (!cluster) { | |
110 | AliError(Form("%s: Could not get cluster %d", GetName(), i)); | |
111 | continue; | |
112 | } | |
113 | if (!AcceptCluster(cluster)) | |
114 | continue; | |
115 | Int_t mcLabel = cluster->GetLabel(); | |
116 | if (mcLabel > 0) { | |
5be3857d | 117 | Int_t index = -1; |
118 | if (mcLabel < fMCParticlesMap->GetSize()) | |
119 | index = fMCParticlesMap->At(mcLabel); | |
5ce8ae64 | 120 | if (index < 0) |
121 | continue; | |
8afc7c8d | 122 | AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index)); |
123 | if (!part) { | |
124 | AliError(Form("%s: Could not get MC particle %d", GetName(), index)); | |
125 | continue; | |
126 | } | |
127 | UInt_t bits = (UInt_t)part->TestBits(TObject::kBitMask); | |
128 | cluster->SetBit(bits); | |
129 | } | |
130 | } | |
131 | } | |
132 | ||
133 | //________________________________________________________________________ | |
134 | void AliJetConstituentTagCopier::DoTrackLoop(TClonesArray *array) | |
135 | { | |
136 | for (Int_t i = 0; i < array->GetEntries(); i++) { | |
137 | AliVParticle *track = static_cast<AliVParticle*>(array->At(i)); | |
138 | if (!track) { | |
139 | AliError(Form("%s: Could not get track %d", GetName(), i)); | |
140 | continue; | |
141 | } | |
142 | if (!AcceptTrack(track)) | |
143 | continue; | |
5ce8ae64 | 144 | Int_t mcLabel = TMath::Abs(track->GetLabel()); |
8afc7c8d | 145 | if (mcLabel != 0) { |
5be3857d | 146 | Int_t index = -1; |
147 | if (mcLabel < fMCParticlesMap->GetSize()) | |
148 | index = fMCParticlesMap->At(mcLabel); | |
5ce8ae64 | 149 | if (index < 0) |
150 | continue; | |
8afc7c8d | 151 | AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index)); |
152 | if (!part) { | |
153 | AliError(Form("%s: Could not get MC particle %d", GetName(), index)); | |
154 | continue; | |
155 | } | |
5ce8ae64 | 156 | AliDebug(2, Form("Track %d, pt = %f, eta = %f, phi = %f, label = %d is matched with particle %d, pt = %f, eta = %f, phi = %f", |
157 | i, track->Pt(), track->Eta(), track->Phi(), mcLabel, index, part->Pt(), part->Eta(), part->Phi())); | |
8afc7c8d | 158 | UInt_t bits = (UInt_t)part->TestBits(TObject::kBitMask); |
159 | track->SetBit(bits); | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | //________________________________________________________________________ | |
165 | void AliJetConstituentTagCopier::DoEmcalParticleLoop(TClonesArray *array) | |
166 | { | |
167 | for (Int_t i = 0; i < array->GetEntries(); i++) { | |
168 | AliEmcalParticle *emcpart = static_cast<AliEmcalParticle*>(array->At(i)); | |
169 | if (!emcpart) { | |
170 | AliError(Form("%s: Could not get EmcalParticle %d", GetName(), i)); | |
171 | continue; | |
172 | } | |
173 | if (!AcceptEmcalPart(emcpart)) | |
174 | continue; | |
175 | AliVCluster *cluster = emcpart->GetCluster(); | |
176 | AliVParticle *track = emcpart->GetTrack(); | |
177 | Int_t mcLabel = 0; | |
178 | if (cluster) | |
179 | mcLabel = cluster->GetLabel(); | |
180 | else if (track) | |
5ce8ae64 | 181 | mcLabel = TMath::Abs(track->GetLabel()); |
8afc7c8d | 182 | if (mcLabel != 0) { |
5be3857d | 183 | Int_t index = -1; |
184 | if (mcLabel < fMCParticlesMap->GetSize()) | |
185 | index = fMCParticlesMap->At(mcLabel); | |
5ce8ae64 | 186 | if (index < 0) |
187 | continue; | |
8afc7c8d | 188 | AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index)); |
189 | if (!part) { | |
190 | AliError(Form("%s: Could not get MC particle %d", GetName(), index)); | |
191 | continue; | |
192 | } | |
193 | UInt_t bits = (UInt_t)part->TestBits(TObject::kBitMask); | |
194 | emcpart->SetBit(bits); | |
195 | } | |
196 | } | |
197 | } |