3 // Track/cluster matcher
5 // Author: C.Loizides, S.Aiola
7 #include "AliEmcalClusTrackMatcherTask.h"
9 #include <TClonesArray.h>
11 #include "AliAODCaloCluster.h"
12 #include "AliESDCaloCluster.h"
13 #include "AliEmcalParticle.h"
15 #include "AliParticleContainer.h"
16 #include "AliPicoTrack.h"
17 #include "AliVCluster.h"
18 #include "AliVTrack.h"
20 ClassImp(AliEmcalClusTrackMatcherTask)
22 //________________________________________________________________________
23 AliEmcalClusTrackMatcherTask::AliEmcalClusTrackMatcherTask() :
24 AliAnalysisTaskEmcal("AliEmcalClusTrackMatcherTask",kFALSE),
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;
44 //________________________________________________________________________
45 AliEmcalClusTrackMatcherTask::AliEmcalClusTrackMatcherTask(const char *name, Bool_t histo) :
46 AliAnalysisTaskEmcal(name,histo),
54 // Standard constructor.
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;
66 //________________________________________________________________________
67 AliEmcalClusTrackMatcherTask::~AliEmcalClusTrackMatcherTask()
72 //________________________________________________________________________
73 void AliEmcalClusTrackMatcherTask::ExecOnce()
75 // Initialize the analysis.
77 if (fParticleCollArray.GetEntriesFast()<2) {
78 AliError(Form("Wrong number of particle collections (%d), required 2",fParticleCollArray.GetEntriesFast()));
82 for (Int_t i = 0; i < 2; i++) {
83 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
84 cont->SetClassName("AliEmcalParticle");
85 // make sure objects are not double matched
86 TClonesArray *dummy = new TClonesArray("TObject",0);
87 dummy->SetName(Form("%s_matched", cont->GetArrayName().Data()));
88 AddObjectToEvent(dummy);
89 // get pointer to original collections
90 TString tmp(cont->GetArrayName());
91 TObjArray *arr = tmp.Tokenize("_");
93 const Int_t aid = arr->GetEntries()-1;
95 TString tname(arr->At(aid)->GetName());
96 TClonesArray *oarr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(tname));
98 AliInfo(Form("Setting orig tracks to %s", tname.Data()));
100 } else if (oarr && (i==1)) {
101 AliInfo(Form("Setting orig clusters to %s", tname.Data()));
109 AliAnalysisTaskEmcal::ExecOnce();
112 //________________________________________________________________________
113 void AliEmcalClusTrackMatcherTask::UserCreateOutputObjects()
115 // Create my user objects.
120 AliAnalysisTaskEmcal::UserCreateOutputObjects();
122 const Int_t nCentChBins = fNcentBins * 2;
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);
129 for(Int_t icent=0; icent<nCentChBins; ++icent) {
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);
134 fHistMatchEta[icent][ipt][ieta]->SetXTitle("#Delta#eta");
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);
137 fHistMatchPhi[icent][ipt][ieta]->SetXTitle("#Delta#phi");
138 fOutput->Add(fHistMatchEta[icent][ipt][ieta]);
139 fOutput->Add(fHistMatchPhi[icent][ipt][ieta]);
144 PostData(1, fOutput);
147 //________________________________________________________________________
148 Int_t AliEmcalClusTrackMatcherTask::GetMomBin(Double_t p) const
155 else if (p>=0.5 && p<1.0)
157 else if (p>=1.0 && p<1.5)
159 else if (p>=1.5 && p<2.)
161 else if (p>=2. && p<3.)
163 else if (p>=3. && p<4.)
165 else if (p>=4. && p<5.)
167 else if (p>=5. && p<8.)
175 //________________________________________________________________________
176 Bool_t AliEmcalClusTrackMatcherTask::Run()
178 // Run the matching for the selected options.
180 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
181 AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
183 AliEmcalParticle *partC = 0;
184 AliEmcalParticle *partT = 0;
186 const Double_t maxd2 = fMaxDistance*fMaxDistance;
188 // set the links between tracks and clusters
189 clusters->ResetCurrentID();
190 while ((partC = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
191 AliVCluster *clust = partC->GetCluster();
193 tracks->ResetCurrentID();
194 while ((partT = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
195 AliVTrack *track = partT->GetTrack();
198 AliPicoTrack::GetEtaPhiDiff(track, clust, dphi, deta);
199 Double_t d2 = deta * deta + dphi * dphi;
203 Double_t d = TMath::Sqrt(d2);
204 partC->AddMatchedObj(tracks->GetCurrentID(), d);
205 partC->SetMatchedPtr(fOrigTracks);
206 partT->AddMatchedObj(clusters->GetCurrentID(), d);
207 partT->SetMatchedPtr(fOrigClus);
210 Int_t mombin = GetMomBin(track->P());
211 Int_t centbinch = fCentBin;
212 if (track->Charge()<0)
213 centbinch += fNcentBins;
218 fHistMatchEta[centbinch][mombin][etabin]->Fill(deta);
219 fHistMatchPhi[centbinch][mombin][etabin]->Fill(dphi);
220 fHistMatchEtaAll->Fill(deta);
221 fHistMatchPhiAll->Fill(dphi);
229 clusters->ResetCurrentID();
230 while ((partC = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
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;
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);
243 ec = dynamic_cast<AliESDCaloCluster*>(clust);
244 TArrayI *arr = ec->GetTracksMatched();
247 const Int_t N = partC->GetNumberOfMatchedObj();
250 const UInt_t matchedId = partC->GetMatchedObjId();
251 partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(matchedId));
252 AliVTrack *track = partT->GetTrack();
255 AliPicoTrack::GetEtaPhiDiff(track, clust, dphi, deta);
256 clust->SetEmcCpvDistance(matchedId);
257 clust->SetTrackDistance(deta, dphi);
259 for (Int_t i=0; i<N; ++i) {
260 Int_t id = partC->GetMatchedObjId(i);
261 partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(id));
262 TObject *obj = partT->GetTrack();
263 ac->AddTrackMatched(obj);
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);
272 ec->AddTracksMatched(arr);
276 tracks->ResetCurrentID();
277 while ((partT = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
278 AliVTrack *track = partT->GetTrack();
279 track->ResetStatus(AliVTrack::kEMCALmatch);
280 if (partT->GetNumberOfMatchedObj() <= 0)
282 partC = static_cast<AliEmcalParticle*>(clusters->GetParticle(partT->GetMatchedObjId()));
283 track->SetEMCALcluster(partC->IdInCollection());
284 track->SetStatus(AliVTrack::kEMCALmatch);