]>
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> | |
10 | #include <TH1I.h> | |
5ce8ae64 | 11 | #include <TMath.h> |
8afc7c8d | 12 | |
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) { | |
65 | fMCParticlesMap = dynamic_cast<TH1I*>(InputEvent()->FindListObject(fMCParticlesName + "_Map")); | |
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())); | |
70 | fMCParticlesMap = new TH1I("tracksMap","tracksMap",9999,0,1); | |
71 | for (Int_t i = 0; i < 9999; i++) { | |
72 | fMCParticlesMap->SetBinContent(i,i); | |
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) { | |
5ce8ae64 | 117 | Int_t index = fMCParticlesMap->At(mcLabel); |
118 | if (index < 0) | |
119 | continue; | |
8afc7c8d | 120 | AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index)); |
121 | if (!part) { | |
122 | AliError(Form("%s: Could not get MC particle %d", GetName(), index)); | |
123 | continue; | |
124 | } | |
125 | UInt_t bits = (UInt_t)part->TestBits(TObject::kBitMask); | |
126 | cluster->SetBit(bits); | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
131 | //________________________________________________________________________ | |
132 | void AliJetConstituentTagCopier::DoTrackLoop(TClonesArray *array) | |
133 | { | |
134 | for (Int_t i = 0; i < array->GetEntries(); i++) { | |
135 | AliVParticle *track = static_cast<AliVParticle*>(array->At(i)); | |
136 | if (!track) { | |
137 | AliError(Form("%s: Could not get track %d", GetName(), i)); | |
138 | continue; | |
139 | } | |
140 | if (!AcceptTrack(track)) | |
141 | continue; | |
5ce8ae64 | 142 | Int_t mcLabel = TMath::Abs(track->GetLabel()); |
8afc7c8d | 143 | if (mcLabel != 0) { |
5ce8ae64 | 144 | Int_t index = fMCParticlesMap->At(mcLabel); |
145 | if (index < 0) | |
146 | continue; | |
8afc7c8d | 147 | AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index)); |
148 | if (!part) { | |
149 | AliError(Form("%s: Could not get MC particle %d", GetName(), index)); | |
150 | continue; | |
151 | } | |
5ce8ae64 | 152 | AliDebug(2, Form("Track %d, pt = %f, eta = %f, phi = %f, label = %d is matched with particle %d, pt = %f, eta = %f, phi = %f", |
153 | i, track->Pt(), track->Eta(), track->Phi(), mcLabel, index, part->Pt(), part->Eta(), part->Phi())); | |
8afc7c8d | 154 | UInt_t bits = (UInt_t)part->TestBits(TObject::kBitMask); |
155 | track->SetBit(bits); | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
160 | //________________________________________________________________________ | |
161 | void AliJetConstituentTagCopier::DoEmcalParticleLoop(TClonesArray *array) | |
162 | { | |
163 | for (Int_t i = 0; i < array->GetEntries(); i++) { | |
164 | AliEmcalParticle *emcpart = static_cast<AliEmcalParticle*>(array->At(i)); | |
165 | if (!emcpart) { | |
166 | AliError(Form("%s: Could not get EmcalParticle %d", GetName(), i)); | |
167 | continue; | |
168 | } | |
169 | if (!AcceptEmcalPart(emcpart)) | |
170 | continue; | |
171 | AliVCluster *cluster = emcpart->GetCluster(); | |
172 | AliVParticle *track = emcpart->GetTrack(); | |
173 | Int_t mcLabel = 0; | |
174 | if (cluster) | |
175 | mcLabel = cluster->GetLabel(); | |
176 | else if (track) | |
5ce8ae64 | 177 | mcLabel = TMath::Abs(track->GetLabel()); |
8afc7c8d | 178 | if (mcLabel != 0) { |
5ce8ae64 | 179 | Int_t index = fMCParticlesMap->At(mcLabel); |
180 | if (index < 0) | |
181 | continue; | |
8afc7c8d | 182 | AliVParticle *part = static_cast<AliVParticle*>(fMCParticles->At(index)); |
183 | if (!part) { | |
184 | AliError(Form("%s: Could not get MC particle %d", GetName(), index)); | |
185 | continue; | |
186 | } | |
187 | UInt_t bits = (UInt_t)part->TestBits(TObject::kBitMask); | |
188 | emcpart->SetBit(bits); | |
189 | } | |
190 | } | |
191 | } |