]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/EMCAL/AliEmcalClusTrackMatcherTask.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalClusTrackMatcherTask.cxx
CommitLineData
aee86258 1// $Id$
980821ba 2//
cd231d42 3// Track/cluster matcher
4//
d258e37e 5// Author: C.Loizides, S.Aiola
aee86258 6
c79b2854 7#include "AliEmcalClusTrackMatcherTask.h"
8
64b4d2f2 9#include <TClonesArray.h>
35789a2d 10
2f78f495 11#include "AliAODCaloCluster.h"
12#include "AliESDCaloCluster.h"
d258e37e 13#include "AliEmcalParticle.h"
35789a2d 14#include "AliLog.h"
2f78f495 15#include "AliParticleContainer.h"
c79b2854 16#include "AliPicoTrack.h"
17#include "AliVCluster.h"
18#include "AliVTrack.h"
aee86258 19
20ClassImp(AliEmcalClusTrackMatcherTask)
21
d258e37e 22//________________________________________________________________________
23AliEmcalClusTrackMatcherTask::AliEmcalClusTrackMatcherTask() :
9239b066 24 AliAnalysisTaskEmcal("AliEmcalClusTrackMatcherTask",kFALSE),
6fba0c3d 25 fMaxDistance(0.1),
2f78f495 26 fModifyObjs(kFALSE),
27 fOrigTracks(0),
28 fOrigClus(0),
3b396909
CL
29 fHistMatchEtaAll(0),
30 fHistMatchPhiAll(0)
d258e37e 31{
32 // Constructor.
938691d1 33
34 for(Int_t icent=0; icent<8; ++icent) {
35 for(Int_t ipt=0; ipt<9; ++ipt) {
36 for(Int_t ieta=0; ieta<2; ++ieta) {
37 fHistMatchEta[icent][ipt][ieta] = 0;
38 fHistMatchPhi[icent][ipt][ieta] = 0;
39 }
40 }
41 }
d258e37e 42}
43
aee86258 44//________________________________________________________________________
938691d1 45AliEmcalClusTrackMatcherTask::AliEmcalClusTrackMatcherTask(const char *name, Bool_t histo) :
9239b066 46 AliAnalysisTaskEmcal(name,histo),
6fba0c3d 47 fMaxDistance(0.1),
2f78f495 48 fModifyObjs(kFALSE),
49 fOrigTracks(0),
50 fOrigClus(0),
3b396909
CL
51 fHistMatchEtaAll(0),
52 fHistMatchPhiAll(0)
aee86258 53{
54 // Standard constructor.
938691d1 55
56 for(Int_t icent=0; icent<8; ++icent) {
57 for(Int_t ipt=0; ipt<9; ++ipt) {
58 for(Int_t ieta=0; ieta<2; ++ieta) {
59 fHistMatchEta[icent][ipt][ieta] = 0;
60 fHistMatchPhi[icent][ipt][ieta] = 0;
61 }
62 }
63 }
aee86258 64}
65
66//________________________________________________________________________
67AliEmcalClusTrackMatcherTask::~AliEmcalClusTrackMatcherTask()
68{
8bec746d 69 // Destructor.
aee86258 70}
71
b6f970ad 72//________________________________________________________________________
73void AliEmcalClusTrackMatcherTask::ExecOnce()
74{
75 // Initialize the analysis.
76
77 if (fParticleCollArray.GetEntriesFast()<2) {
78 AliError(Form("Wrong number of particle collections (%d), required 2",fParticleCollArray.GetEntriesFast()));
79 return;
80 }
81
82 for (Int_t i = 0; i < 2; i++) {
83 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
84 cont->SetClassName("AliEmcalParticle");
2f78f495 85 // make sure objects are not double matched
86 TClonesArray *dummy = new TClonesArray("TObject",0);
4e507e3a 87 dummy->SetName(Form("%s_matched", cont->GetArrayName().Data()));
2f78f495 88 AddObjectToEvent(dummy);
4e507e3a 89 // get pointer to original collections
a6440e25 90 TString tmp(cont->GetArrayName());
2f78f495 91 TObjArray *arr = tmp.Tokenize("_");
92 if (arr) {
93 const Int_t aid = arr->GetEntries()-1;
94 if (aid>0) {
a6440e25 95 TString tname(arr->At(aid)->GetName());
96 TClonesArray *oarr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(tname));
97 if (oarr && (i==0)) {
98 AliInfo(Form("Setting orig tracks to %s", tname.Data()));
2f78f495 99 fOrigTracks = oarr;
a6440e25 100 } else if (oarr && (i==1)) {
101 AliInfo(Form("Setting orig clusters to %s", tname.Data()));
2f78f495 102 fOrigClus = oarr;
a6440e25 103 }
2f78f495 104 }
105 }
106 delete arr;
b6f970ad 107 }
108
9239b066 109 AliAnalysisTaskEmcal::ExecOnce();
b6f970ad 110}
111
938691d1 112//________________________________________________________________________
113void AliEmcalClusTrackMatcherTask::UserCreateOutputObjects()
114{
115 // Create my user objects.
116
117 if (!fCreateHisto)
118 return;
119
9239b066 120 AliAnalysisTaskEmcal::UserCreateOutputObjects();
938691d1 121
6fd2f1a9 122 const Int_t nCentChBins = fNcentBins * 2;
123
3b396909
CL
124 fHistMatchEtaAll = new TH1F("fHistMatchEtaAll", "fHistMatchEtaAll", 400, -0.2, 0.2);
125 fHistMatchPhiAll = new TH1F("fHistMatchPhiAll", "fHistMatchPhiAll", 400, -0.2, 0.2);
126 fOutput->Add(fHistMatchEtaAll);
127 fOutput->Add(fHistMatchPhiAll);
128
6fd2f1a9 129 for(Int_t icent=0; icent<nCentChBins; ++icent) {
938691d1 130 for(Int_t ipt=0; ipt<9; ++ipt) {
131 for(Int_t ieta=0; ieta<2; ++ieta) {
132 TString nameEta(Form("fHistMatchEta_%i_%i_%i",icent,ipt,ieta));
133 fHistMatchEta[icent][ipt][ieta] = new TH1F(nameEta, nameEta, 400, -0.2, 0.2);
caa49ef8 134 fHistMatchEta[icent][ipt][ieta]->SetXTitle("#Delta#eta");
938691d1 135 TString namePhi(Form("fHistMatchPhi_%i_%i_%i",icent,ipt,ieta));
136 fHistMatchPhi[icent][ipt][ieta] = new TH1F(namePhi, namePhi, 400, -0.2, 0.2);
caa49ef8 137 fHistMatchPhi[icent][ipt][ieta]->SetXTitle("#Delta#phi");
938691d1 138 fOutput->Add(fHistMatchEta[icent][ipt][ieta]);
139 fOutput->Add(fHistMatchPhi[icent][ipt][ieta]);
140 }
141 }
142 }
143
144 PostData(1, fOutput);
145}
146
147//________________________________________________________________________
148Int_t AliEmcalClusTrackMatcherTask::GetMomBin(Double_t p) const
149{
150 // Get momenum bin.
151
152 Int_t pbin=-1;
153 if (p<0.5)
154 pbin=0;
155 else if (p>=0.5 && p<1.0)
156 pbin=1;
157 else if (p>=1.0 && p<1.5)
158 pbin=2;
159 else if (p>=1.5 && p<2.)
160 pbin=3;
161 else if (p>=2. && p<3.)
162 pbin=4;
163 else if (p>=3. && p<4.)
164 pbin=5;
165 else if (p>=4. && p<5.)
166 pbin=6;
167 else if (p>=5. && p<8.)
168 pbin=7;
169 else if (p>=8.)
170 pbin=8;
171
172 return pbin;
173}
174
aee86258 175//________________________________________________________________________
d258e37e 176Bool_t AliEmcalClusTrackMatcherTask::Run()
aee86258 177{
d258e37e 178 // Run the matching for the selected options.
6421eeb0 179
b6f970ad 180 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
181 AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
e3d22acf 182
b6f970ad 183 AliEmcalParticle *partC = 0;
184 AliEmcalParticle *partT = 0;
56bd3193 185
ef46ebe5 186 const Double_t maxd2 = fMaxDistance*fMaxDistance;
187
188 // set the links between tracks and clusters
b6f970ad 189 clusters->ResetCurrentID();
190 while ((partC = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
191 AliVCluster *clust = partC->GetCluster();
56bd3193 192
b6f970ad 193 tracks->ResetCurrentID();
194 while ((partT = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
195 AliVTrack *track = partT->GetTrack();
d258e37e 196 Double_t deta = 999;
197 Double_t dphi = 999;
c79b2854 198 AliPicoTrack::GetEtaPhiDiff(track, clust, dphi, deta);
e3d22acf 199 Double_t d2 = deta * deta + dphi * dphi;
c79b2854 200 if (d2 > maxd2)
201 continue;
56bd3193 202
c79b2854 203 Double_t d = TMath::Sqrt(d2);
b6f970ad 204 partC->AddMatchedObj(tracks->GetCurrentID(), d);
2f78f495 205 partC->SetMatchedPtr(fOrigTracks);
b6f970ad 206 partT->AddMatchedObj(clusters->GetCurrentID(), d);
2f78f495 207 partT->SetMatchedPtr(fOrigClus);
208
938691d1 209 if (fCreateHisto) {
210 Int_t mombin = GetMomBin(track->P());
211 Int_t centbinch = fCentBin;
212 if (track->Charge()<0)
6fd2f1a9 213 centbinch += fNcentBins;
938691d1 214 Int_t etabin = 0;
215 if(track->Eta() > 0)
216 etabin = 1;
217
218 fHistMatchEta[centbinch][mombin][etabin]->Fill(deta);
219 fHistMatchPhi[centbinch][mombin][etabin]->Fill(dphi);
3b396909
CL
220 fHistMatchEtaAll->Fill(deta);
221 fHistMatchPhiAll->Fill(dphi);
938691d1 222 }
aee86258 223 }
aee86258 224 }
c79b2854 225
2f78f495 226 if (!fModifyObjs)
227 return kTRUE;
228
b6f970ad 229 clusters->ResetCurrentID();
230 while ((partC = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
2f78f495 231 AliVCluster *clust = partC->GetCluster();
232 clust->SetEmcCpvDistance(-1);
233 clust->SetTrackDistance(1024, 1024);
234 AliAODCaloCluster *ac = dynamic_cast<AliAODCaloCluster*>(clust);
235 AliESDCaloCluster *ec = 0;
236 if (ac) {
237 const Int_t N = ac->GetNTracksMatched();
238 for (Int_t i=N-1; i>=0; --i) {
239 TObject *ptr = ac->GetTrackMatched(i);
240 ac->RemoveTrackMatched(ptr);
241 }
242 } else {
243 ec = dynamic_cast<AliESDCaloCluster*>(clust);
244 TArrayI *arr = ec->GetTracksMatched();
2b0c2d87 245 if(arr) arr->Set(0);
2f78f495 246 }
247 const Int_t N = partC->GetNumberOfMatchedObj();
248 if (N <= 0)
c79b2854 249 continue;
250 const UInt_t matchedId = partC->GetMatchedObjId();
b6f970ad 251 partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(matchedId));
2f78f495 252 AliVTrack *track = partT->GetTrack();
c79b2854 253 Double_t deta = 999;
254 Double_t dphi = 999;
255 AliPicoTrack::GetEtaPhiDiff(track, clust, dphi, deta);
256 clust->SetEmcCpvDistance(matchedId);
257 clust->SetTrackDistance(deta, dphi);
2f78f495 258 if (ac) {
259 for (Int_t i=0; i<N; ++i) {
260 Int_t id = partC->GetMatchedObjId(i);
4be0c532 261 partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(id));
262 TObject *obj = partT->GetTrack();
2f78f495 263 ac->AddTrackMatched(obj);
4be0c532 264 }
265 } else {
266 TArrayI arr(N);
267 for (Int_t i=0; i<N; ++i) {
268 Int_t id = partC->GetMatchedObjId(i);
269 partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(id));
270 arr.AddAt(partT->IdInCollection(),i);
271 }
272 ec->AddTracksMatched(arr);
2f78f495 273 }
c79b2854 274 }
b6f970ad 275
276 tracks->ResetCurrentID();
277 while ((partT = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
2f78f495 278 AliVTrack *track = partT->GetTrack();
279 track->ResetStatus(AliVTrack::kEMCALmatch);
c79b2854 280 if (partT->GetNumberOfMatchedObj() <= 0)
281 continue;
4be0c532 282 partC = static_cast<AliEmcalParticle*>(clusters->GetParticle(partT->GetMatchedObjId()));
283 track->SetEMCALcluster(partC->IdInCollection());
2f78f495 284 track->SetStatus(AliVTrack::kEMCALmatch);
c79b2854 285 }
a18c300f 286
287 return kTRUE;
aee86258 288}