AliPhysics  v5-07-15-01 (b3d7633)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEmcalClusTrackMatcherTask.cxx
Go to the documentation of this file.
1 // $Id$
2 //
3 // Track/cluster matcher
4 //
5 // Author: C.Loizides, S.Aiola
6 
8 
9 #include <TClonesArray.h>
10 
11 #include "AliAODCaloCluster.h"
12 #include "AliESDCaloCluster.h"
13 #include "AliEmcalParticle.h"
14 #include "AliLog.h"
15 #include "AliParticleContainer.h"
16 #include "AliPicoTrack.h"
17 #include "AliVCluster.h"
18 #include "AliVTrack.h"
19 
21 
22 //________________________________________________________________________
25  fMaxDistance(0.1),
26  fModifyObjs(kFALSE),
27  fOrigTracks(0),
28  fOrigClus(0),
29  fHistMatchEtaAll(0),
30  fHistMatchPhiAll(0)
31 {
32  // Constructor.
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  }
42 }
43 
44 //________________________________________________________________________
46  AliAnalysisTaskEmcal(name,histo),
47  fMaxDistance(0.1),
48  fModifyObjs(kFALSE),
49  fOrigTracks(0),
50  fOrigClus(0),
51  fHistMatchEtaAll(0),
52  fHistMatchPhiAll(0)
53 {
54  // Standard constructor.
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  }
64 }
65 
66 //________________________________________________________________________
68 {
69  // Destructor.
70 }
71 
72 //________________________________________________________________________
74 {
75  // Initialize the analysis.
76 
78  if(!fInitialized) return;
79 
80  if (fParticleCollArray.GetEntriesFast()<2) {
81  AliError(Form("Wrong number of particle collections (%d), required 2",fParticleCollArray.GetEntriesFast()));
82  return;
83  }
84 
85  for (Int_t i = 0; i < 2; i++) {
87  cont->SetClassName("AliEmcalParticle");
88  // make sure objects are not double matched
89  TClonesArray *dummy = new TClonesArray("TObject",0);
90  dummy->SetName(Form("%s_matched", cont->GetArrayName().Data()));
91  AddObjectToEvent(dummy);
92  // get pointer to original collections
93  TString tmp(cont->GetArrayName());
94  TObjArray *arr = tmp.Tokenize("_");
95  if (arr) {
96  const Int_t aid = arr->GetEntries()-1;
97  if (aid>0) {
98  TString tname(arr->At(aid)->GetName());
99  TClonesArray *oarr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(tname));
100  if (oarr && (i==0)) {
101  AliInfo(Form("Setting orig tracks to %s", tname.Data()));
102  fOrigTracks = oarr;
103  } else if (oarr && (i==1)) {
104  AliInfo(Form("Setting orig clusters to %s", tname.Data()));
105  fOrigClus = oarr;
106  }
107  }
108  }
109  delete arr;
110  }
111 
112 }
113 
114 //________________________________________________________________________
116 {
117  // Create my user objects.
118 
119  if (!fCreateHisto)
120  return;
121 
123 
124  const Int_t nCentChBins = fNcentBins * 2;
125 
126  fHistMatchEtaAll = new TH1F("fHistMatchEtaAll", "fHistMatchEtaAll", 400, -0.2, 0.2);
127  fHistMatchPhiAll = new TH1F("fHistMatchPhiAll", "fHistMatchPhiAll", 400, -0.2, 0.2);
130 
131  for(Int_t icent=0; icent<nCentChBins; ++icent) {
132  for(Int_t ipt=0; ipt<9; ++ipt) {
133  for(Int_t ieta=0; ieta<2; ++ieta) {
134  TString nameEta(Form("fHistMatchEta_%i_%i_%i",icent,ipt,ieta));
135  fHistMatchEta[icent][ipt][ieta] = new TH1F(nameEta, nameEta, 400, -0.2, 0.2);
136  fHistMatchEta[icent][ipt][ieta]->SetXTitle("#Delta#eta");
137  TString namePhi(Form("fHistMatchPhi_%i_%i_%i",icent,ipt,ieta));
138  fHistMatchPhi[icent][ipt][ieta] = new TH1F(namePhi, namePhi, 400, -0.2, 0.2);
139  fHistMatchPhi[icent][ipt][ieta]->SetXTitle("#Delta#phi");
140  fOutput->Add(fHistMatchEta[icent][ipt][ieta]);
141  fOutput->Add(fHistMatchPhi[icent][ipt][ieta]);
142  }
143  }
144  }
145 
146  PostData(1, fOutput);
147 }
148 
149 //________________________________________________________________________
151 {
152  // Get momenum bin.
153 
154  Int_t pbin=-1;
155  if (p<0.5)
156  pbin=0;
157  else if (p>=0.5 && p<1.0)
158  pbin=1;
159  else if (p>=1.0 && p<1.5)
160  pbin=2;
161  else if (p>=1.5 && p<2.)
162  pbin=3;
163  else if (p>=2. && p<3.)
164  pbin=4;
165  else if (p>=3. && p<4.)
166  pbin=5;
167  else if (p>=4. && p<5.)
168  pbin=6;
169  else if (p>=5. && p<8.)
170  pbin=7;
171  else if (p>=8.)
172  pbin=8;
173 
174  return pbin;
175 }
176 
177 //________________________________________________________________________
179 {
180  // Run the matching for the selected options.
181 
182  AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
183  AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
184 
185  AliEmcalParticle *partC = 0;
186  AliEmcalParticle *partT = 0;
187 
188  const Double_t maxd2 = fMaxDistance*fMaxDistance;
189 
190  // set the links between tracks and clusters
191  clusters->ResetCurrentID();
192  while ((partC = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
193  AliVCluster *clust = partC->GetCluster();
194 
195  tracks->ResetCurrentID();
196  while ((partT = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
197  AliVTrack *track = partT->GetTrack();
198  Double_t deta = 999;
199  Double_t dphi = 999;
200  AliPicoTrack::GetEtaPhiDiff(track, clust, dphi, deta);
201  Double_t d2 = deta * deta + dphi * dphi;
202  if (d2 > maxd2)
203  continue;
204 
205  Double_t d = TMath::Sqrt(d2);
206  partC->AddMatchedObj(tracks->GetCurrentID(), d);
207  partC->SetMatchedPtr(fOrigTracks);
208  partT->AddMatchedObj(clusters->GetCurrentID(), d);
209  partT->SetMatchedPtr(fOrigClus);
210 
211  if (fCreateHisto) {
212  Int_t mombin = GetMomBin(track->P());
213  Int_t centbinch = fCentBin;
214  if (track->Charge()<0)
215  centbinch += fNcentBins;
216  Int_t etabin = 0;
217  if(track->Eta() > 0)
218  etabin = 1;
219 
220  fHistMatchEta[centbinch][mombin][etabin]->Fill(deta);
221  fHistMatchPhi[centbinch][mombin][etabin]->Fill(dphi);
222  fHistMatchEtaAll->Fill(deta);
223  fHistMatchPhiAll->Fill(dphi);
224  }
225  }
226  }
227 
228  if (!fModifyObjs)
229  return kTRUE;
230 
231  clusters->ResetCurrentID();
232  while ((partC = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
233  AliVCluster *clust = partC->GetCluster();
234  clust->SetEmcCpvDistance(-1);
235  clust->SetTrackDistance(1024, 1024);
236  AliAODCaloCluster *ac = dynamic_cast<AliAODCaloCluster*>(clust);
237  AliESDCaloCluster *ec = 0;
238  if (ac) {
239  const Int_t N = ac->GetNTracksMatched();
240  for (Int_t i=N-1; i>=0; --i) {
241  TObject *ptr = ac->GetTrackMatched(i);
242  ac->RemoveTrackMatched(ptr);
243  }
244  } else {
245  ec = dynamic_cast<AliESDCaloCluster*>(clust);
246  TArrayI *arr = ec->GetTracksMatched();
247  if(arr) arr->Set(0);
248  }
249  const Int_t N = partC->GetNumberOfMatchedObj();
250  if (N <= 0)
251  continue;
252  const UInt_t matchedId = partC->GetMatchedObjId();
253  partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(matchedId));
254  AliVTrack *track = partT->GetTrack();
255  Double_t deta = 999;
256  Double_t dphi = 999;
257  AliPicoTrack::GetEtaPhiDiff(track, clust, dphi, deta);
258  clust->SetEmcCpvDistance(matchedId);
259  clust->SetTrackDistance(deta, dphi);
260  if (ac) {
261  for (Int_t i=0; i<N; ++i) {
262  Int_t id = partC->GetMatchedObjId(i);
263  partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(id));
264  TObject *obj = partT->GetTrack();
265  ac->AddTrackMatched(obj);
266  }
267  } else {
268  TArrayI arr(N);
269  for (Int_t i=0; i<N; ++i) {
270  Int_t id = partC->GetMatchedObjId(i);
271  partT = static_cast<AliEmcalParticle*>(tracks->GetParticle(id));
272  arr.AddAt(partT->IdInCollection(),i);
273  }
274  ec->AddTracksMatched(arr);
275  }
276  }
277 
278  tracks->ResetCurrentID();
279  while ((partT = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
280  AliVTrack *track = partT->GetTrack();
281  track->ResetStatus(AliVTrack::kEMCALmatch);
282  if (partT->GetNumberOfMatchedObj() <= 0)
283  continue;
284  partC = static_cast<AliEmcalParticle*>(clusters->GetParticle(partT->GetMatchedObjId()));
285  track->SetEMCALcluster(partC->IdInCollection());
286  track->SetStatus(AliVTrack::kEMCALmatch);
287  }
288 
289  return kTRUE;
290 }
TClonesArray * fOrigClus
ptr to original tracks (used if fModifyObjs true)
Int_t GetMatchedObjId(UShort_t i=0) const
UShort_t GetNumberOfMatchedObj() const
void SetClassName(const char *clname)
void SetMatchedPtr(TObjArray *arr)
TH1 * fHistMatchPhi[8][9][2]
deta distribution
void AddObjectToEvent(TObject *obj)
Int_t fCentBin
event centrality
AliVTrack * GetTrack() const
TList * fOutput
x-section from pythia header
AliVParticle * GetParticle(Int_t i) const
Int_t GetCurrentID() const
Int_t IdInCollection() const
AliVParticle * GetNextAcceptParticle(Int_t i=-1)
TH1 * fHistMatchEta[8][9][2]
dphi distribution
const TString & GetArrayName() const
ClassImp(AliEmcalClusTrackMatcherTask) AliEmcalClusTrackMatcherTask
AliVCluster * GetCluster() const
void AddMatchedObj(Int_t id, Double_t d)
static void GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
TH1 * fHistMatchEtaAll
ptr to original clusters (used if fModifyObjs true)
void ResetCurrentID(Int_t i=0)