]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/totEt/AliAnalysisEmEtReconstructed.cxx
Update in cuts for Sigma* and update for lego_train macros (M.Vala)
[u/mrichter/AliRoot.git] / PWGLF / totEt / AliAnalysisEmEtReconstructed.cxx
1 //_________________________________________________________________________
2 //  Utility Class for transverse energy studies
3 //  Base class for MC analysis
4 //  - MC output
5 //  implementation file
6 //
7 //*-- Author: Marcelo G. Munhoz (USP)
8               //_________________________________________________________________________
9
10 #include "AliAnalysisEmEtReconstructed.h"
11 #include "AliAnalysisEtCuts.h"
12 #include "AliESDtrack.h"
13 #include "AliStack.h"
14 #include "AliVEvent.h"
15 #include "AliMCEvent.h"
16 #include "AliESDEvent.h"
17 #include "TH2F.h"
18 #include "TParticle.h"
19 #include "AliGenHijingEventHeader.h"
20 #include "AliGenPythiaEventHeader.h"
21 #include "TList.h"
22 #include "AliESDCaloCluster.h"
23 #include "TGeoGlobalMagField.h"
24 #include "AliMagF.h"
25 #include "AliEMCALTrack.h"
26 #include "AliESDtrackCuts.h"
27 #include "AliEMCALGeometry.h"
28 #include "AliExternalTrackParam.h"
29 #include "AliTrackerBase.h"
30 #include "TGeoManager.h"
31
32   using namespace std;
33
34 ClassImp(AliAnalysisEmEtReconstructed);
35
36
37 // ctor
38 AliAnalysisEmEtReconstructed::AliAnalysisEmEtReconstructed():AliAnalysisEtReconstructed()
39                                                             ,fAllRectotETDep(0)
40                                                             ,fElectronMatchtotETDep(0)
41                                                             ,fNeutralRectotET(0)
42                                                             ,fTotEMRectotET(0)
43
44                                                             ,fMuonMatchtotETDep(0), fPionMatchtotETDep(0), fKaonMatchtotETDep(0), fProtonMatchtotETDep(0)
45                                                             ,fTotChargedMatchtotETDep(0)
46
47                                                             ,fTotalRectotETDep(0)
48
49                                                             ,fESD(0)
50                                                             ,fGeoUt(0)
51
52                                                             ,fHistAllRecETDep(0) 
53                                                             ,fHistAllRec(0) 
54                                                             ,fHistAllRectotETDep(0) 
55
56                                                             ,fHistElectronRecETDep(0) 
57                                                             ,fHistElectronRec(0) 
58                                                             ,fHistElectronMatchtotETDep(0) 
59                                                             ,fHistElectronRecdEdxP(0)
60
61                                                             ,fHistNeutralRectotET(0)  
62
63                                                             ,fHistTotEMRectotET(0)
64
65                                                             ,fHistMuonRecETDep(0) 
66                                                             ,fHistMuonRec(0) 
67                                                             ,fHistMuonMatchtotETDep(0) 
68                                                             ,fHistMuonRecdEdxP(0)
69
70                                                             ,fHistPionRecETDep(0) 
71                                                             ,fHistPionRec(0) 
72                                                             ,fHistPionMatchtotETDep(0) 
73                                                             ,fHistPionRecdEdxP(0)
74
75                                                             ,fHistKaonRecETDep(0) 
76                                                             ,fHistKaonRec(0) 
77                                                             ,fHistKaonMatchtotETDep(0) 
78                                                             ,fHistKaonRecdEdxP(0)
79
80                                                             ,fHistProtonRecETDep(0) 
81                                                             ,fHistProtonRec(0) 
82                                                             ,fHistProtonMatchtotETDep(0) 
83                                                             ,fHistProtonRecdEdxP(0)
84
85                                                             ,fHistTotChargedMatchtotETDep(0)
86
87                                                             ,fHistTotalRectotETDep(0)
88
89                                                             ,fHistDeltaRZ(0)
90 {//constructor
91   fHistogramNameSuffix = TString("EmcalRec");
92         
93   fResCut = 0.02;
94   //fResCut = fEmcalTrackDistanceCut;
95         
96   TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", -1., -1., AliMagF::k5kG));
97   //TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", 1., 1., AliMagF::k5kG));
98   TGeoManager::Import("geometry.root");
99 }
100
101 // dtor
102 AliAnalysisEmEtReconstructed::~AliAnalysisEmEtReconstructed() 
103 {//Destructor 
104   delete fGeoUt;
105
106   delete fHistAllRecETDep;
107   delete fHistAllRec;
108   delete fHistAllRectotETDep;
109         
110   delete fHistElectronRecETDep;
111   delete fHistElectronRec;
112   delete fHistElectronMatchtotETDep; 
113         
114   delete fHistElectronRecdEdxP;
115
116   delete fHistNeutralRectotET;  
117
118   delete fHistTotEMRectotET;
119
120   delete fHistMuonRecETDep;
121   delete fHistMuonRec;
122   delete fHistMuonMatchtotETDep; 
123
124   delete fHistMuonRecdEdxP;
125         
126   delete fHistPionRecETDep;
127   delete fHistPionRec;
128   delete fHistPionMatchtotETDep; 
129
130   delete fHistPionRecdEdxP;
131
132   delete fHistKaonRecETDep;
133   delete fHistKaonRec;
134   delete fHistKaonMatchtotETDep; 
135
136   delete fHistKaonRecdEdxP;
137         
138   delete fHistProtonRecETDep;
139   delete fHistProtonRec;
140   delete fHistProtonMatchtotETDep; 
141
142   delete fHistProtonRecdEdxP;
143         
144   delete fHistTotChargedMatchtotETDep;
145         
146   delete fHistTotalRectotETDep;
147         
148   //few checks
149   delete fHistDeltaRZ;
150         
151 }
152
153 Int_t AliAnalysisEmEtReconstructed::AnalyseEvent(AliVEvent* ev)
154 { // analyse MC and real event info
155   if(!ev){
156     AliError("ERROR: Event does not exist");   
157     return 0;
158   }
159         
160   fESD = dynamic_cast<AliESDEvent*>(ev);
161
162   if(!fGeoUt){
163     fGeoUt = AliEMCALGeometry::GetInstance("EMCAL_FIRSTYEARV1");//new AliEMCALGeometry("EMCAL_FIRSTYEAR","EMCAL");
164     //fGeoUt = AliEMCALGeometry::GetInstance("EMCAL_COMPLETEV1");
165     AliInfo("Creating new AliEMCALGeometry");
166   }
167   //fGeoUt = new AliEMCALGeometry("EMCAL_COMPLETE1","EMCAL");
168   if(!fGeoUt){
169     AliInfo("No fGeoUt!");
170   }
171   else{
172     if(!fESD->GetEMCALMatrix(0)){
173       AliInfo("No matrix!");
174     }
175     else{
176       fGeoUt->SetMisalMatrix(fESD->GetEMCALMatrix(0),0);
177     }
178   }
179         
180   ResetEventValues();
181         
182   // get all emcal clusters
183   TRefArray* caloClusters = new TRefArray();
184   fESD->GetEMCALClusters( caloClusters );
185         
186   Int_t nCluster = caloClusters->GetEntries();
187         
188   Float_t pos[3] = {0};
189   TVector3 caloPos(0,0,0);
190   TVector3 trackPos(0,0,0);
191   Double_t res=0, delta_eta=0, delta_phi=0, maxPid=-99;
192   Double_t xCluster[4]={0}, xCharged[7]={0};
193         
194   AliESDtrack *track = 0;
195     
196   // loop the clusters
197   for (int iCluster = 0; iCluster < nCluster; iCluster++ ) 
198     {           
199       // Retrieve calo cluster information
200       AliESDCaloCluster* caloCluster = ( AliESDCaloCluster* )caloClusters->At( iCluster );
201       Float_t caloE = caloCluster->E();
202       caloCluster->GetPosition(pos);            
203       caloPos.SetXYZ(pos[0],pos[1],pos[2]);
204                 
205       // look for track that matches calo cluster  
206       //track = FindMatch(caloCluster, res); // Marcelo's matching      
207
208       // *********************
209       // tender's matching
210       delta_eta = caloCluster->GetTrackDz(); 
211       delta_phi = caloCluster->GetTrackDx(); 
212
213       if (caloCluster->GetTrackMatchedIndex() > 0) // tender's matching
214           track = fESD->GetTrack(caloCluster->GetTrackMatchedIndex());
215         
216       //if (track)
217       //   if ( !fEsdtrackCutsITSTPC->IsSelected(track) )
218       //       track = 0;
219       // *********************
220         
221       // Retrieve track PID
222       if (track)
223         maxPid = GetTrackPID(track);
224       else
225         maxPid = -99;
226                 
227       // calculate ET
228       Double_t etDep = CalculateTransverseEnergy(caloCluster);
229                 
230       // All clusters
231       //fHistAllRecEtaEDepETDep->Fill(caloE,caloPos.Eta(),etDep);
232       //fHistAllRecEtaETDep->Fill(etDep,caloPos.Eta());
233                 
234       xCluster[0] = caloE;
235       xCluster[1] = caloPos.Eta();
236       xCluster[2] = TMath::RadToDeg()*caloPos.Phi();
237       xCluster[3] = caloCluster->GetNCells();
238       fAllRectotETDep += etDep;         
239                 
240         
241       if(fMakeSparse){
242         fHistAllRecETDep->Fill(xCluster,etDep);
243         fHistAllRec->Fill(xCluster);
244       }
245
246       if (track)
247         {
248           xCharged[0] = track->Eta();
249           xCharged[1] = track->Pt();
250         }
251       else
252         {
253           xCharged[0] = -99;
254           xCharged[1] = -99;
255         }
256       xCharged[2] = caloE;
257       xCharged[3] = caloPos.Eta();
258       xCharged[4] = TMath::RadToDeg()*caloPos.Phi();
259       xCharged[5] = caloCluster->GetNCells();
260       xCharged[6] = res;
261                 
262       Bool_t isCharged = kFALSE;
263                 
264       if (maxPid == AliPID::kProton)
265         {
266                         
267           if(fMakeSparse){
268             fHistProtonRecETDep->Fill(xCharged,etDep);
269             fHistProtonRec->Fill(xCharged);
270           }
271
272           fHistProtonRecdEdxP->Fill(track->P(),track->GetTPCsignal());
273                         
274           if ((res>0.) && (res<fResCut))
275             {
276               fProtonMatchtotETDep += etDep;
277
278               isCharged = kTRUE;
279             }
280         }
281       else if (maxPid == AliPID::kPion)
282         {
283                         
284           if(fMakeSparse){
285             fHistPionRecETDep->Fill(xCharged,etDep);
286             fHistPionRec->Fill(xCharged);
287           }
288
289           fHistPionRecdEdxP->Fill(track->P(),track->GetTPCsignal());
290                         
291           if ((res>0.) && (res<fResCut))
292             {
293               fPionMatchtotETDep += etDep;
294               isCharged = kTRUE;
295             }
296         }
297       else if (maxPid == AliPID::kKaon)
298         {
299                         
300           if(fMakeSparse){
301             fHistKaonRecETDep->Fill(xCharged,etDep);
302             fHistKaonRec->Fill(xCharged);
303           }
304
305           fHistKaonRecdEdxP->Fill(track->P(),track->GetTPCsignal());
306                         
307           if ((res>0.) && (res<fResCut))
308             {
309
310               fKaonMatchtotETDep += etDep;
311               isCharged = kTRUE;
312             }
313         }
314       else if (maxPid == AliPID::kMuon)
315         {
316                         
317           if(fMakeSparse){
318             fHistMuonRecETDep->Fill(xCharged,etDep);
319             fHistMuonRec->Fill(xCharged);
320           }
321           fHistMuonRecdEdxP->Fill(track->P(),track->GetTPCsignal());
322                         
323           if ((res>0.) && (res<fResCut))
324             {
325
326               fMuonMatchtotETDep += etDep;                                              
327               isCharged = kTRUE;
328             }
329         }
330       else if (maxPid == AliPID::kElectron)
331         {
332                         
333           if(fMakeSparse){
334             fHistElectronRecETDep->Fill(xCharged,etDep);
335             fHistElectronRec->Fill(xCharged);
336           }
337
338           fHistElectronRecdEdxP->Fill(track->P(),track->GetTPCsignal());
339                         
340           if ((res>0.) && (res<fResCut))
341             {
342               fElectronMatchtotETDep += etDep;
343               isCharged = kTRUE;
344             }
345         }
346                 
347       if (!isCharged)
348         {
349           fNeutralRectotET += etDep;                    
350         }
351                 
352     } // end of loop over clusters      
353         
354   fTotEMRectotET = fElectronMatchtotETDep + fNeutralRectotET;
355   fTotChargedMatchtotETDep = fMuonMatchtotETDep + fPionMatchtotETDep + fKaonMatchtotETDep + fProtonMatchtotETDep;
356   fTotalRectotETDep = fTotEMRectotET + fTotChargedMatchtotETDep;
357         
358   fHistAllRectotETDep->Fill(fAllRectotETDep);
359         
360   fHistElectronMatchtotETDep->Fill(fElectronMatchtotETDep); 
361   fHistNeutralRectotET->Fill(fNeutralRectotET);
362         
363   fHistTotEMRectotET->Fill(fTotEMRectotET);
364         
365   fHistMuonMatchtotETDep->Fill(fMuonMatchtotETDep); 
366   fHistPionMatchtotETDep->Fill(fPionMatchtotETDep); 
367   fHistKaonMatchtotETDep->Fill(fKaonMatchtotETDep); 
368   fHistProtonMatchtotETDep->Fill(fProtonMatchtotETDep); 
369   fHistTotChargedMatchtotETDep->Fill(fTotChargedMatchtotETDep);
370         
371   fHistTotalRectotETDep->Fill(fTotalRectotETDep);
372         
373   delete caloClusters;
374         
375   return 0;    
376 }
377
378 void AliAnalysisEmEtReconstructed::Init()
379 { // init
380   AliAnalysisEt::Init();
381 }
382
383
384 void AliAnalysisEmEtReconstructed::ResetEventValues()
385 { // reset event values
386   AliAnalysisEt::ResetEventValues();
387         
388   // collision geometry defaults for p+p:
389   fAllRectotETDep = 0;
390         
391   fElectronMatchtotETDep = 0;
392   fNeutralRectotET = 0;
393         
394   fTotEMRectotET = 0;
395         
396   fMuonMatchtotETDep = 0; fPionMatchtotETDep = 0; fKaonMatchtotETDep = 0; fProtonMatchtotETDep = 0;
397   fTotChargedMatchtotETDep = 0;
398         
399   fTotalRectotETDep = 0;
400 }
401
402
403 void AliAnalysisEmEtReconstructed::CreateHistograms()
404 { // histogram related additions
405   //AliAnalysisEt::CreateHistograms();
406         
407   if(fMakeSparse){
408     fHistAllRecETDep = CreateClusterHistoSparse("fHistAllRecETDep_","E_{T}, all particles");
409     fHistAllRec = CreateClusterHistoSparse("fHistAllRec_","counts, all particles");
410   }
411   TString histname = "fHistAllRectotETDep_" + fHistogramNameSuffix;
412   fHistAllRectotETDep = new TH1F(histname.Data(),"total ET, all particles",fgNumOfEBins, fgEAxis);
413
414
415   if(fMakeSparse){
416     fHistElectronRecETDep = CreateChargedPartHistoSparse("fHistElectronRecETDep_","E_{T}, electrons");
417     fHistElectronRec = CreateChargedPartHistoSparse("fHistElectronRec_","counts, electrons");
418   }
419   histname = "fHistElectronMatchtotETDep_" + fHistogramNameSuffix;
420   fHistElectronMatchtotETDep = new TH1F(histname.Data(),"total ET, MC primary Electrons",fgNumOfEBins, fgEAxis);
421
422   histname = "fHistElectronRecdEdxP_" + fHistogramNameSuffix;
423   fHistElectronRecdEdxP = new TH2F(histname,"TPC dEdx vs P",100,0.,10.,100,0.,200.);
424
425   histname = "fHistNeutralRectotET_" + fHistogramNameSuffix;
426   fHistNeutralRectotET = new TH1F(histname.Data(),"total ET, neutral particles",fgNumOfEBins, fgEAxis);
427         
428   histname = "fHistTotEMRectotET_" + fHistogramNameSuffix;
429   fHistTotEMRectotET = new TH1F(histname.Data(),"total electromagnetic ET",fgNumOfEBins, fgEAxis);
430
431   if(fMakeSparse){
432     fHistMuonRecETDep = CreateChargedPartHistoSparse("fHistMuonRecETDep_","E_{T}, muons");
433     fHistMuonRec = CreateChargedPartHistoSparse("fHistMuonRec_","counts, muons");
434   }
435   histname = "fHistMuonMatchtotETDep_" + fHistogramNameSuffix;
436   fHistMuonMatchtotETDep = new TH1F(histname.Data(),"total ET, Muons",fgNumOfEBins, fgEAxis);
437
438   histname = "fHistMuonRecdEdxP_" + fHistogramNameSuffix;
439   fHistMuonRecdEdxP = new TH2F(histname,"TPC dEdx vs P",100,0.,10.,100,0.,200.);
440         
441   if(fMakeSparse){
442     fHistPionRecETDep = CreateChargedPartHistoSparse("fHistPionRecETDep_","E_{T}, pions");
443     fHistPionRec = CreateChargedPartHistoSparse("fHistPionRec_","counts, pions");
444   }
445   histname = "fHistPionMatchtotETDep_" + fHistogramNameSuffix;
446   fHistPionMatchtotETDep = new TH1F(histname.Data(),"total ET, Pions",fgNumOfEBins, fgEAxis);
447   histname = "fHistPionRecdEdxP_" + fHistogramNameSuffix;
448   fHistPionRecdEdxP = new TH2F(histname,"TPC dEdx vs P",100,0.,10.,100,0.,200.);
449         
450   if(fMakeSparse){
451     fHistKaonRecETDep = CreateChargedPartHistoSparse("fHistKaonRecETDep_","E_{T}, kaons");
452     fHistKaonRec = CreateChargedPartHistoSparse("fHistKaonRec_","counts, kaons");
453   }
454   histname = "fHistKaonMatchtotETDep_" + fHistogramNameSuffix;
455   fHistKaonMatchtotETDep = new TH1F(histname.Data(),"total ET, Kaons",fgNumOfEBins, fgEAxis);
456
457   histname = "fHistKaonRecdEdxP_" + fHistogramNameSuffix;
458   fHistKaonRecdEdxP = new TH2F(histname,"TPC dEdx vs P",100,0.,10.,100,0.,200.);
459         
460   if(fMakeSparse){
461     fHistProtonRecETDep = CreateChargedPartHistoSparse("fHistProtonRecETDep_","E_{T}, protons");
462     fHistProtonRec = CreateChargedPartHistoSparse("fHistProtonRec_","counts, protons");
463   }
464   histname = "fHistProtonMatchtotETDep_" + fHistogramNameSuffix;
465   fHistProtonMatchtotETDep = new TH1F(histname.Data(),"total ET, Protons",fgNumOfEBins, fgEAxis);
466
467   histname = "fHistProtonRecdEdxP_" + fHistogramNameSuffix;
468   fHistProtonRecdEdxP = new TH2F(histname,"TPC dEdx vs P",100,0.,10.,100,0.,200.);
469         
470   histname = "fHistTotChargedMatchtotETDep_" + fHistogramNameSuffix;
471   fHistTotChargedMatchtotETDep = new TH1F(histname.Data(),"total ET, charged particles",fgNumOfEBins, fgEAxis);
472         
473   histname = "fHistTotalRectotETDep_" + fHistogramNameSuffix;
474   fHistTotalRectotETDep = new TH1F(histname.Data(),"total ET, all particles",fgNumOfEBins, fgEAxis);            
475         
476   histname = "fHistDeltaRZ_" + fHistogramNameSuffix;
477   fHistDeltaRZ = new TH2F(histname,"#Delta#phi vs #Delta#eta (track projection - cluster position)",200,-0.1,0.1,200,-0.1,0.1);
478 }
479
480 void AliAnalysisEmEtReconstructed::FillOutputList(TList *list)
481 {//Function for filling the output list
482   //AliAnalysisEt::FillOutputList(list);
483         
484         
485   if(fMakeSparse){
486     list->Add(fHistAllRecETDep); 
487     list->Add(fHistAllRec); 
488   }
489   list->Add(fHistAllRectotETDep); 
490
491   if(fMakeSparse){
492     list->Add(fHistElectronRecETDep); 
493     list->Add(fHistElectronRec); 
494   }
495   list->Add(fHistElectronMatchtotETDep); 
496   list->Add(fHistElectronRecdEdxP);
497         
498         
499   list->Add(fHistTotEMRectotET); 
500
501   list->Add(fHistMuonRec); 
502   list->Add(fHistMuonRecdEdxP);
503   list->Add(fHistMuonMatchtotETDep); 
504
505   if(fMakeSparse){
506     list->Add(fHistPionRecETDep); 
507     list->Add(fHistPionRec); 
508   }
509   list->Add(fHistPionMatchtotETDep); 
510   list->Add(fHistPionRecdEdxP);
511         
512   if(fMakeSparse){
513     list->Add(fHistKaonRecETDep); 
514     list->Add(fHistKaonRec); 
515   }
516   list->Add(fHistKaonMatchtotETDep); 
517   list->Add(fHistKaonRecdEdxP);
518
519   if(fMakeSparse){
520     list->Add(fHistProtonRecETDep); 
521     list->Add(fHistProtonRec); 
522   }
523   list->Add(fHistProtonMatchtotETDep); 
524   list->Add(fHistProtonRecdEdxP);
525         
526   list->Add(fHistTotChargedMatchtotETDep); 
527   list->Add(fHistTotalRectotETDep); 
528         
529   list->Add(fHistDeltaRZ);
530 }
531
532 //________________________________________________________________________
533 //project to a EMCal radius
534 Bool_t AliAnalysisEmEtReconstructed::GetTrackProjection(AliExternalTrackParam *trackParam, TVector3 &trackPos)
535 {//Gets the projection of the track
536   Bool_t proj = kFALSE;
537   Double_t emcalR = fGeoUt->GetEMCGeometry()->GetIPDistance();
538         
539   if (trackParam) //it is constructed from TParticle
540     {
541       Double_t trkPos[3] = {0};
542                 
543       //Assume the track is a pion with mass 0.139GeV/c^2
544       //Extrapolation step is 1cm
545       if(!AliTrackerBase::PropagateTrackToBxByBz(trackParam, emcalR, 0.139, 1, kTRUE, 0.8) ) return proj;
546                 
547       trackParam->GetXYZ(trkPos);
548                 
549       trackPos.SetXYZ(trkPos[0],trkPos[1],trkPos[2]);
550                 
551       proj = kTRUE;               
552     }
553         
554   return proj;
555 }
556
557 //________________________________________________________________________
558 //project to a cluster position
559 Bool_t AliAnalysisEmEtReconstructed::GetTrackProjection(AliEMCALTrack* emcTrack, TVector3 &trackPos, TVector3 clusPos)
560 {//project to a cluster position
561   Bool_t proj = kFALSE;
562         
563   if (emcTrack)
564     {   
565       Double_t trkPos[3] = {0};
566                 
567       emcTrack->PropagateToGlobal(clusPos.X(),clusPos.Y(),clusPos.Z(),0.,0.);
568       emcTrack->GetXYZ(trkPos);
569                 
570       trackPos.SetXYZ(trkPos[0],trkPos[1],trkPos[2]);
571                 
572       proj = kTRUE;
573     }
574         
575   return proj;
576 }
577
578 //________________________________________________________________________      
579 AliESDtrack* AliAnalysisEmEtReconstructed::FindMatch(const AliESDCaloCluster *caloCluster, Double_t& resMin)
580 {//find a matched track
581   Double_t res=0;
582   resMin=999;
583         
584   TVector3 caloPos(0,0,0);
585   Float_t pos[3] = {0};
586   caloCluster->GetPosition(pos);                
587   caloPos.SetXYZ(pos[0],pos[1],pos[2]);
588         
589   // loop over tracks
590   TVector3 trackPos(0,0,0);
591   TVector3 trackMatchPos(0,0,0);
592   AliEMCALTrack *emcTrack = 0;  
593   AliESDtrack *trackMatch = 0;  
594         
595   TObjArray* list = fEsdtrackCutsITSTPC->GetAcceptedTracks(fESD);;
596   Int_t nGoodTracks = list->GetEntries();
597         
598   for (Int_t iTrack = 0; iTrack < nGoodTracks; iTrack++) 
599     {
600       AliESDtrack *track = dynamic_cast<AliESDtrack*> (list->At(iTrack));
601       if (!track)
602         {
603           AliError(Form("ERROR: Could not get track %d", iTrack));
604           continue;
605         }
606                 
607       emcTrack = new AliEMCALTrack(*track);
608                 
609       if (GetTrackProjection(emcTrack,trackPos,caloPos))
610         {
611           res = sqrt(pow(trackPos.Phi()-caloPos.Phi(),2)+pow(trackPos.Eta()-caloPos.Eta(),2));
612                         
613           if (res < resMin)
614             {
615               resMin = res;
616               trackMatch = track;
617               trackMatchPos.SetXYZ(trackPos.X(),trackPos.Y(),trackPos.Z());
618             }
619         }
620                 
621       delete emcTrack;
622     }           
623         
624   fHistDeltaRZ->Fill(trackMatchPos.Phi()-caloPos.Phi(),trackMatchPos.Eta()-caloPos.Eta());
625
626   return trackMatch;
627 }
628
629 //________________________________________________________________________      
630 Double_t AliAnalysisEmEtReconstructed::GetTrackPID(const AliESDtrack *track) const
631 {//Get the default track ID
632   const Double_t *pidWeights = track->PID();
633   Int_t maxpid = -1;
634   Double_t maxpidweight = 0;
635         
636   if (pidWeights)
637     {
638       for (Int_t p =0; p < AliPID::kSPECIES; p++)
639         {
640           if (pidWeights[p] > maxpidweight)
641             {
642               maxpidweight = pidWeights[p];
643               maxpid = p;
644             }
645         }
646     }
647         
648   return maxpid;
649 }