AliPhysics  9c66e61 (9c66e61)
AliCaloTrackMatcher.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: Daniel Mühlheim *
5  * Version 1.0 *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
17 //---------------------------------------------
18 // Basic Track Matching Class
19 //---------------------------------------------
21 
22 
23 #include "AliAnalysisManager.h"
24 #include "AliAODEvent.h"
25 #include "AliCaloTrackMatcher.h"
26 #include "AliEMCALRecoUtils.h"
27 #include "AliESDEvent.h"
28 #include "AliESDtrack.h"
29 #include "AliESDtrackCuts.h"
30 #include "AliInputEventHandler.h"
31 #include "AliTrackerBase.h"
32 #include "AliV0ReaderV1.h"
33 
34 #include "TAxis.h"
35 #include "TChain.h"
36 #include "TH1F.h"
37 #include "TF1.h"
38 
39 #include <vector>
40 #include <map>
41 #include <utility>
42 
43 class iostream;
44 
45 using namespace std;
46 
47 
48 ClassImp(AliCaloTrackMatcher)
49 
50 //________________________________________________________________________
51 AliCaloTrackMatcher::AliCaloTrackMatcher(const char *name, Int_t clusterType, Int_t runningMode) : AliAnalysisTaskSE(name),
52  fClusterType(clusterType),
53  fRunningMode(runningMode),
54  fV0ReaderName(""),
55  fCorrTaskSetting(""),
56  fAnalysisTrainMode("Grid"),
57  fMatchingWindow(200),
58  fMatchingResidual(0.2),
59  fRunNumber(-1),
60  fGeomEMCAL(NULL),
61  fGeomPHOS(NULL),
62  fMapTrackToCluster(),
63  fMapClusterToTrack(),
64  fNEntries(1),
65  fVectorDeltaEtaDeltaPhi(0),
66  fMap_TrID_ClID_ToIndex(),
67  fSecMapTrackToCluster(),
68  fSecMapClusterToTrack(),
69  fSecNEntries(1),
70  fSecVectorDeltaEtaDeltaPhi(0),
71  fSecMap_TrID_ClID_ToIndex(),
72  fSecMap_TrID_ClID_AlreadyTried(),
73  fListHistos(NULL),
74  fHistControlMatches(NULL),
75  fSecHistControlMatches(NULL)
76 {
77  // Default constructor
78  DefineInput(0, TChain::Class());
79 
80  if( !(fRunningMode == 0 || fRunningMode == 1 || fRunningMode == 2 || fRunningMode == 5 || fRunningMode == 6) )
81  AliFatal(Form("AliCaloTrackMatcher: Running mode not defined: '%d' ! Please set a proper mode in the AddTask, returning...",fRunningMode));
82 }
83 
84 //________________________________________________________________________
86  // default deconstructor
87  fMapTrackToCluster.clear();
88  fMapClusterToTrack.clear();
89  fVectorDeltaEtaDeltaPhi.clear();
90  fMap_TrID_ClID_ToIndex.clear();
91 
92  fSecMapTrackToCluster.clear();
93  fSecMapClusterToTrack.clear();
94  fSecVectorDeltaEtaDeltaPhi.clear();
95  fSecMap_TrID_ClID_ToIndex.clear();
96  fSecMap_TrID_ClID_AlreadyTried.clear();
97 
98  if(fHistControlMatches) delete fHistControlMatches;
99  if(fSecHistControlMatches) delete fSecHistControlMatches;
100  if(fAnalysisTrainMode.EqualTo("Grid")){
101  if(fListHistos != NULL){
102  delete fListHistos;
103  }
104  }
105 }
106 
107 //________________________________________________________________________
109  fMapTrackToCluster.clear();
110  fMapClusterToTrack.clear();
111  fVectorDeltaEtaDeltaPhi.clear();
112  fMap_TrID_ClID_ToIndex.clear();
113 
114  fSecMapTrackToCluster.clear();
115  fSecMapClusterToTrack.clear();
116  fSecVectorDeltaEtaDeltaPhi.clear();
117  fSecMap_TrID_ClID_ToIndex.clear();
118  fSecMap_TrID_ClID_AlreadyTried.clear();
119 }
120 
121 //________________________________________________________________________
123  if(fListHistos != NULL){
124  delete fListHistos;
125  fListHistos = NULL;
126  }
127  if(fListHistos == NULL){
128  fListHistos = new TList();
129  fListHistos->SetOwner(kTRUE);
130  fListHistos->SetName(Form("CaloTrackMatcher_%i_%i",fClusterType,fRunningMode));
131  }
132 
133  // Create User Output Objects
134  fHistControlMatches = new TH2F(Form("ControlMatches_%i_%i",fClusterType,fRunningMode),Form("ControlMatches_%i_%i",fClusterType,fRunningMode),7,-0.5,6.5,50,0.05,200.0);
135  SetLogBinningYTH2(fHistControlMatches);
136  fHistControlMatches->GetYaxis()->SetTitle("track pT (GeV/c)");
137  fHistControlMatches->GetXaxis()->SetBinLabel(1,"nTr in");
138  fHistControlMatches->GetXaxis()->SetBinLabel(2,"no inner Tr params || track not in right direction");
139  fHistControlMatches->GetXaxis()->SetBinLabel(3,"failed 1st pro-step");
140  fHistControlMatches->GetXaxis()->SetBinLabel(4,"Tr not in EMCal acc");
141  fHistControlMatches->GetXaxis()->SetBinLabel(5,"failed 2nd pro-step");
142  fHistControlMatches->GetXaxis()->SetBinLabel(6,"w/o match to cluster");
143  fHistControlMatches->GetXaxis()->SetBinLabel(7,"nTr out, w/ match");
144  fListHistos->Add(fHistControlMatches);
145 
146  fSecHistControlMatches = new TH2F(Form("ControlSecMatches_%i_%i",fClusterType,fRunningMode),Form("ControlSecMatches_%i_%i",fClusterType,fRunningMode),7,-0.5,6.5,50,0.05,200.0);
147  SetLogBinningYTH2(fSecHistControlMatches);
148  fSecHistControlMatches->GetYaxis()->SetTitle("track pT (GeV/c)");
149  fSecHistControlMatches->GetXaxis()->SetBinLabel(1,"nTr in");
150  fSecHistControlMatches->GetXaxis()->SetBinLabel(2,"no inner Tr params || track not in right direction");
151  fSecHistControlMatches->GetXaxis()->SetBinLabel(3,"failed 1st pro-step");
152  fSecHistControlMatches->GetXaxis()->SetBinLabel(4,"Tr not in EMCal acc");
153  fSecHistControlMatches->GetXaxis()->SetBinLabel(5,"failed 2nd pro-step");
154  fSecHistControlMatches->GetXaxis()->SetBinLabel(6,"w/o match to cluster");
155  fSecHistControlMatches->GetXaxis()->SetBinLabel(7,"nTr out, w/ match");
156  fListHistos->Add(fSecHistControlMatches);
157 }
158 
159 //________________________________________________________________________
161  // Initialize function to be called once before analysis
162  fMapTrackToCluster.clear();
163  fMapClusterToTrack.clear();
164  fNEntries = 1;
165  fVectorDeltaEtaDeltaPhi.clear();
166  fMap_TrID_ClID_ToIndex.clear();
167 
168  fSecMapTrackToCluster.clear();
169  fSecMapClusterToTrack.clear();
170  fSecNEntries = 1;
171  fSecVectorDeltaEtaDeltaPhi.clear();
172  fSecMap_TrID_ClID_ToIndex.clear();
173  fSecMap_TrID_ClID_AlreadyTried.clear();
174 
175  if(fRunNumber == -1 || fRunNumber != runNumber){
176  if(fClusterType == 1 || fClusterType == 3){
177  fGeomEMCAL = AliEMCALGeometry::GetInstanceFromRunNumber(runNumber);
178  if(!fGeomEMCAL){ AliFatal("EMCal geometry not initialized!");}
179  }else if(fClusterType == 2){
180  fGeomPHOS = AliPHOSGeometry::GetInstance();
181  if(!fGeomPHOS) AliFatal("PHOS geometry not initialized!");
182  }
183  fRunNumber = runNumber;
184  }
185 }
186 
187 //________________________________________________________________________
189 
190  // main method of AliCaloTrackMatcher, first initialize and then process event
191 
192  //DebugV0Matching();
193 
194  // do processing only for EMCal (1), DCal (3) or PHOS (2) clusters, otherwise do nothing
195  if(fClusterType == 1 || fClusterType == 2 || fClusterType == 3){
196  Initialize(fInputEvent->GetRunNumber());
197  ProcessEvent(fInputEvent);
198  }
199 
200  //DebugMatching();
201 
202  return;
203 }
204 
205 //________________________________________________________________________
206 void AliCaloTrackMatcher::ProcessEvent(AliVEvent *event){
207  Int_t nClus = 0;
208  TClonesArray * arrClusters = NULL;
209  if(!fCorrTaskSetting.CompareTo("")){
210  nClus = event->GetNumberOfCaloClusters();
211  } else {
212  arrClusters = dynamic_cast<TClonesArray*>(event->FindListObject(Form("%sClustersBranch",fCorrTaskSetting.Data())));
213  if(arrClusters){
214  nClus = arrClusters->GetEntries();
215  }else{
216  AliError(Form("Could not find %sClustersBranch despite correction framework being used!",fCorrTaskSetting.Data()));
217  return;
218  }
219  }
220  Int_t nModules = 0;
221  if(fClusterType == 1 || fClusterType == 3) nModules = fGeomEMCAL->GetNumberOfSuperModules();
222  else if(fClusterType == 2) nModules = fGeomPHOS->GetNModules();
223 
224  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(event);
225  AliAODEvent *aodev = 0;
226  if (!esdev) {
227  aodev = dynamic_cast<AliAODEvent*>(event);
228  if (!aodev) {
229  AliError("Task needs AOD or ESD event, returning");
230  return;
231  }
232  }
233  static AliESDtrackCuts *EsdTrackCuts = 0x0;
234  static int prevRun = -1;
235  // Using standard function for setting Cuts
236  if (esdev && (fRunningMode == 0 || fRunningMode == 6)){
237  Int_t runNumber = fInputEvent->GetRunNumber();
238  if (prevRun!=runNumber) {
239  delete EsdTrackCuts;
240  EsdTrackCuts = 0;
241  prevRun = runNumber;
242  }
243  if (!EsdTrackCuts) {
244  // if LHC11a or earlier or if LHC13g or if LHC12a-i -> use 2010 cuts
245  if( (runNumber<=146860) || (runNumber>=197470 && runNumber<=197692) || (runNumber>=172440 && runNumber<=193766) ){
246  if(fRunningMode == 6) EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kFALSE);
247  else EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
248  // else if run2 data use 2015 PbPb cuts
249  } else if (runNumber>=209122){
250  //EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2015PbPb();
251  // hard coded track cuts for the moment, because AliESDtrackCuts::GetStandardITSTPCTrackCuts2015PbPb() gives spams warnings
252  EsdTrackCuts = new AliESDtrackCuts();
253  // TPC; clusterCut = 1, cutAcceptanceEdges = kTRUE, removeDistortedRegions = kFALSE
254  EsdTrackCuts->AliESDtrackCuts::SetMinNCrossedRowsTPC(70);
255  EsdTrackCuts->AliESDtrackCuts::SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
256  EsdTrackCuts->SetCutGeoNcrNcl(2., 130., 1.5, 0.0, 0.0); // only dead zone and not clusters per length
257  //EsdTrackCuts->AliESDtrackCuts::SetCutOutDistortedRegionsTPC(kTRUE);
258  EsdTrackCuts->AliESDtrackCuts::SetMaxChi2PerClusterTPC(4);
259  EsdTrackCuts->AliESDtrackCuts::SetAcceptKinkDaughters(kFALSE);
260  EsdTrackCuts->AliESDtrackCuts::SetRequireTPCRefit(kTRUE);
261  // ITS; selPrimaries = 1
262  EsdTrackCuts->AliESDtrackCuts::SetRequireITSRefit(kTRUE);
263  EsdTrackCuts->AliESDtrackCuts::SetClusterRequirementITS(AliESDtrackCuts::kSPD,
264  AliESDtrackCuts::kAny);
265  if(fRunningMode != 6){
266  EsdTrackCuts->AliESDtrackCuts::SetMaxDCAToVertexXYPtDep("0.0105+0.0350/pt^1.1");
267  EsdTrackCuts->AliESDtrackCuts::SetMaxChi2TPCConstrainedGlobal(36);
268  }
269  EsdTrackCuts->AliESDtrackCuts::SetMaxDCAToVertexZ(2);
270  EsdTrackCuts->AliESDtrackCuts::SetDCAToVertex2D(kFALSE);
271  EsdTrackCuts->AliESDtrackCuts::SetRequireSigmaToVertex(kFALSE);
272  EsdTrackCuts->AliESDtrackCuts::SetMaxChi2PerClusterITS(36);
273  // else use 2011 version of track cuts
274  }else{
275  if(fRunningMode == 6) EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(kFALSE);
276  else EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011();
277  }
278  EsdTrackCuts->SetMaxDCAToVertexZ(2);
279  }
280  }
281 
282  for (Int_t itr=0;itr<event->GetNumberOfTracks();itr++){
283  AliExternalTrackParam *trackParam = 0;
284  AliVTrack *inTrack = 0x0;
285  if(esdev){
286  inTrack = esdev->GetTrack(itr);
287  if(!inTrack) continue;
288  fHistControlMatches->Fill(0.,inTrack->Pt());
289  AliESDtrack *esdt = dynamic_cast<AliESDtrack*>(inTrack);
290 
291  if(fRunningMode == 0){
292  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 )){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
293  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
294  if(inTrack->Pt()<0.5){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
295  if(!EsdTrackCuts->AcceptTrack(esdt)) {fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
296  }else if(fRunningMode == 5 || fRunningMode == 6){
297  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 )){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
298  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
299  if(inTrack->Pt()<0.3){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
300 
301  if(fRunningMode == 6){
302  if(!EsdTrackCuts->AcceptTrack(esdt)) {fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
303  }
304  }
305 
306  const AliExternalTrackParam *in = esdt->GetInnerParam();
307  if (!in){AliDebug(2, "Could not get InnerParam of Track, continue"); fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
308  trackParam = new AliExternalTrackParam(*in);
309  } else if(aodev) {
310  inTrack = dynamic_cast<AliVTrack*>(aodev->GetTrack(itr));
311  if(!inTrack) continue;
312  fHistControlMatches->Fill(0.,inTrack->Pt());
313  AliAODTrack *aodt = dynamic_cast<AliAODTrack*>(inTrack);
314 
315  if(fRunningMode == 0){
316  if(inTrack->GetID()<0){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;} // Avoid double counting of tracks
317  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 )){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
318  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
319  if(inTrack->Pt()<0.5){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
320  if(!aodt->IsHybridGlobalConstrainedGlobal()){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
321  }else if(fRunningMode == 5 || fRunningMode == 6){
322  if(inTrack->GetID()<0){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;} // Avoid double counting of tracks
323  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 )){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
324  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
325  if(inTrack->Pt()<0.3){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
326 
327  if(fRunningMode == 6){
328  if(!aodt->IsHybridGlobalConstrainedGlobal()){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
329  }
330  }
331 
332  Double_t xyz[3] = {0}, pxpypz[3] = {0}, cv[21] = {0};
333  aodt->GetPxPyPz(pxpypz);
334  aodt->GetXYZ(xyz);
335  aodt->GetCovarianceXYZPxPyPz(cv);
336 
337  // check for EMC tracks already propagated tracks are out of bounds
338  if (fClusterType == 1 || fClusterType == 3){
339  if( TMath::Abs(aodt->GetTrackEtaOnEMCal()) > 0.75 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
340 
341  // conditions for run1
342  if( fClusterType == 1 && nModules < 13 && ( aodt->GetTrackPhiOnEMCal() < 70*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 190*TMath::DegToRad())){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
343 
344  // conditions for run2
345  if( nModules > 12 ){
346  if( fClusterType == 3 && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad()) ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
347  if( fClusterType == 1 && ( aodt->GetTrackPhiOnEMCal() < 70*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 190*TMath::DegToRad()) ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
348  }
349  }
350  trackParam = new AliExternalTrackParam(xyz,pxpypz,cv,aodt->Charge());
351  }
352 
353  if (!trackParam) {AliError("Could not get TrackParameters, continue"); fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
354  AliExternalTrackParam emcParam(*trackParam);
355  Float_t eta, phi, pt;
356 
357  //propagate tracks to emc surfaces
358  if(fClusterType == 1 || fClusterType == 3){
359  if (!AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcParam, 440., 0.139, 20., eta, phi, pt)) {
360  delete trackParam;
361  fHistControlMatches->Fill(2.,inTrack->Pt());
362  continue;
363  }
364  if( TMath::Abs(eta) > 0.75 ) {
365  delete trackParam;
366  fHistControlMatches->Fill(3.,inTrack->Pt());
367  continue;
368  }
369  // Save some time and memory in case of no DCal present
370  if( fClusterType == 1 && nModules < 13 && ( phi < 70*TMath::DegToRad() || phi > 190*TMath::DegToRad())){
371  delete trackParam;
372  fHistControlMatches->Fill(3.,inTrack->Pt());
373  continue;
374  }
375  // Save some time and memory in case of run2
376  if( nModules > 12 ){
377  if (fClusterType == 3 && ( phi < 250*TMath::DegToRad() || phi > 340*TMath::DegToRad())){
378  delete trackParam;
379  fHistControlMatches->Fill(3.,inTrack->Pt());
380  continue;
381  }
382  if( fClusterType == 1 && ( phi < 70*TMath::DegToRad() || phi > 190*TMath::DegToRad())){
383  delete trackParam;
384  fHistControlMatches->Fill(3.,inTrack->Pt());
385  continue;
386  }
387  }
388  }else if(fClusterType == 2){
389  if( !AliTrackerBase::PropagateTrackToBxByBz(&emcParam, 460., 0.139, 20, kTRUE, 0.8, -1)){
390  delete trackParam;
391  fHistControlMatches->Fill(2.,inTrack->Pt());
392  continue;
393  }
394 
395  if (TMath::Abs(eta) > 0.25 && (fClusterType == 2)){
396  delete trackParam;
397  fHistControlMatches->Fill(3.,inTrack->Pt());
398  continue;
399  }
400  }
401 
402  Float_t dEta=-999, dPhi=-999;
403  Float_t clsPos[3] = {0.,0.,0.};
404  Double_t exPos[3] = {0.,0.,0.};
405  if (!emcParam.GetXYZ(exPos)){
406  delete trackParam;
407  fHistControlMatches->Fill(2.,inTrack->Pt());
408  continue;
409  }
410 
411  // cout << inTrack->GetID() << " - " << trackParam << endl;
412  // cout << "eta/phi: " << eta << ", " << phi << endl;
413  // cout << "nClus: " << nClus << endl;
414  Int_t nClusterMatchesToTrack = 0;
415  for(Int_t iclus=0;iclus < nClus;iclus++){
416  AliVCluster* cluster = NULL;
417  if(arrClusters){
418  if(esdev){
419  if(arrClusters)
420  cluster = new AliESDCaloCluster(*(AliESDCaloCluster*)arrClusters->At(iclus));
421  } else if(aodev){
422  if(arrClusters)
423  cluster = new AliAODCaloCluster(*(AliAODCaloCluster*)arrClusters->At(iclus));
424  }
425  }
426  else
427  cluster = event->GetCaloCluster(iclus);
428  if (!cluster){
429  if(arrClusters) delete cluster;
430  continue;
431  }
432  // cout << "-------------------------LOOPING: " << iclus << ", " << cluster->GetID() << endl;
433  cluster->GetPosition(clsPos);
434  Double_t dR = TMath::Sqrt(TMath::Power(exPos[0]-clsPos[0],2)+TMath::Power(exPos[1]-clsPos[1],2)+TMath::Power(exPos[2]-clsPos[2],2));
435  //cout << "dR: " << dR << endl;
436  if (dR > fMatchingWindow){
437  if(arrClusters) delete cluster;
438  continue;
439  }
440  Double_t clusterR = TMath::Sqrt( clsPos[0]*clsPos[0] + clsPos[1]*clsPos[1] );
441  AliExternalTrackParam trackParamTmp(emcParam);//Retrieve the starting point every time before the extrapolation
442  if(fClusterType == 1 || fClusterType == 3){
443  if (!cluster->IsEMCAL()){
444  if(arrClusters) delete cluster;
445  continue;
446  }
447  if(!AliEMCALRecoUtils::ExtrapolateTrackToCluster(&trackParamTmp, cluster, 0.139, 5., dEta, dPhi)){
448  fHistControlMatches->Fill(4.,inTrack->Pt());
449  if(arrClusters) delete cluster;
450  continue;
451  }
452  }else if(fClusterType == 2){
453  if (!cluster->IsPHOS()){
454  if(arrClusters) delete cluster;
455  continue;
456  }
457  if(!AliTrackerBase::PropagateTrackToBxByBz(&trackParamTmp, clusterR, 0.139, 5., kTRUE, 0.8, -1)){
458  fHistControlMatches->Fill(4.,inTrack->Pt());
459  if(arrClusters) delete cluster;
460  continue;
461  }
462  Double_t trkPos[3] = {0,0,0};
463  trackParamTmp.GetXYZ(trkPos);
464  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
465  TVector3 clsPosVec(clsPos);
466  dPhi = clsPosVec.DeltaPhi(trkPosVec);
467  dEta = clsPosVec.Eta()-trkPosVec.Eta();
468  }
469 
470  Float_t dR2 = dPhi*dPhi + dEta*dEta;
471 
472  //cout << dEta << " - " << dPhi << " - " << dR2 << endl;
473  if(dR2 > fMatchingResidual){
474  if(arrClusters) delete cluster;
475  continue;
476  }
477  nClusterMatchesToTrack++;
478  if(aodev){
479  fMapTrackToCluster.insert(make_pair(itr,cluster->GetID()));
480  fMapClusterToTrack.insert(make_pair(cluster->GetID(),itr));
481  }else{
482  fMapTrackToCluster.insert(make_pair(inTrack->GetID(),cluster->GetID()));
483  fMapClusterToTrack.insert(make_pair(cluster->GetID(),inTrack->GetID()));
484  }
485  fVectorDeltaEtaDeltaPhi.push_back(make_pair(dEta,dPhi));
486  fMap_TrID_ClID_ToIndex[make_pair(inTrack->GetID(),cluster->GetID())] = fNEntries++;
487  if( (Int_t)fVectorDeltaEtaDeltaPhi.size() != (fNEntries-1)) AliFatal("Fatal error in AliCaloTrackMatcher, vector and map are not in sync!");
488  if(arrClusters) delete cluster;
489  }
490  if(nClusterMatchesToTrack == 0) fHistControlMatches->Fill(5.,inTrack->Pt());
491  else fHistControlMatches->Fill(6.,inTrack->Pt());
492  delete trackParam;
493  }
494 
495  return;
496 }
497 
498 //________________________________________________________________________
499 Bool_t AliCaloTrackMatcher::PropagateV0TrackToClusterAndGetMatchingResidual(AliVTrack* inSecTrack, AliVCluster* cluster, AliVEvent* event, Float_t &dEta, Float_t &dPhi){
500 
501  //if V0-track to cluster match is already available return stored residuals
502  if(GetSecTrackClusterMatchingResidual(inSecTrack->GetID(),cluster->GetID(), dEta, dPhi)){
503  //cout << "RESIDUAL ALREADY AVAILABLE! - " << dEta << "/" << dPhi << endl;
504  return kTRUE;
505  }
506 
507  if(IsSecTrackClusterAlreadyTried(inSecTrack->GetID(),cluster->GetID())){
508  //cout << "PROPAGATION ALREADY FAILED! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
509  return kFALSE;
510  }
511 
512  //cout << "running matching! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
513  //if match has not yet been computed, go on:
514  Int_t nModules = 0;
515  if(fClusterType == 1 || fClusterType == 3) nModules = fGeomEMCAL->GetNumberOfSuperModules();
516  else if(fClusterType == 2) nModules = fGeomPHOS->GetNModules();
517 
518  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(event);
519  AliAODEvent *aodev = 0;
520  if (!esdev) {
521  aodev = dynamic_cast<AliAODEvent*>(event);
522  if (!aodev) {
523  AliError("Task needs AOD or ESD event, returning");
524  return kFALSE;
525  }
526  }
527 
528  if(!cluster->IsEMCAL() && !cluster->IsPHOS()){AliError("Cluster is neither EMCAL nor PHOS, returning");return kFALSE;}
529 
530  Float_t clusterPosition[3] = {0,0,0};
531  cluster->GetPosition(clusterPosition);
532  Double_t clusterR = TMath::Sqrt( clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1] );
533 
534  if(!inSecTrack) return kFALSE;
535  fSecHistControlMatches->Fill(0.,inSecTrack->Pt());
536 
537  if (inSecTrack->Pt() < 0.3 ) {
538  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
539  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
540  return kFALSE;
541  }
542 
543  AliESDtrack *esdt = dynamic_cast<AliESDtrack*>(inSecTrack);
544  AliAODTrack *aodt = 0;
545  if (!esdt) {
546  aodt = dynamic_cast<AliAODTrack*>(inSecTrack);
547  if (!aodt){
548  AliError("Track is neither ESD nor AOD, continue");
549  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
550  return kFALSE;
551  }
552  }
553 
554  AliExternalTrackParam *trackParam = 0;
555  if (esdt) {
556  const AliExternalTrackParam *in = esdt->GetInnerParam();
557  if (!in){
558  AliDebug(2, "Could not get InnerParam of Track, continue");
559  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
560  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
561  return kFALSE;
562  }
563  trackParam = new AliExternalTrackParam(*in);
564  } else {
565  // check if tracks should be propagated at all
566  if (fClusterType == 1 || fClusterType == 3){
567  if (TMath::Abs(aodt->GetTrackEtaOnEMCal()) > 0.8){
568  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
569  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
570  return kFALSE;
571  }
572  if( nModules < 13 ){
573  if (( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())){
574  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
575  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
576  return kFALSE;
577  }
578  } else if( nModules > 12 ){
579  if (fClusterType == 3 && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad())){
580  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
581  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
582  return kFALSE;
583  }
584  if( fClusterType == 1 && ( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())){
585  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
586  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
587  return kFALSE;
588  }
589  }
590  } else {
591  if ( aodt->Phi() < 60*TMath::DegToRad() || aodt->Phi() > 200*TMath::DegToRad()){
592  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
593  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
594  return kFALSE;
595  }
596  if (TMath::Abs(aodt->Eta()) > 0.3 ){
597  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
598  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
599  return kFALSE;
600  }
601  }
602 
603  Double_t xyz[3] = {0}, pxpypz[3] = {0}, cv[21] = {0};
604  aodt->GetPxPyPz(pxpypz);
605  aodt->GetXYZ(xyz);
606  aodt->GetCovarianceXYZPxPyPz(cv);
607  trackParam = new AliExternalTrackParam(xyz,pxpypz,cv,aodt->Charge());
608  }
609  if(!trackParam){
610  AliError("Could not get TrackParameters, continue");
611  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
612  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
613  return kFALSE;
614  }
615 
616  Bool_t propagated = kFALSE;
617  AliExternalTrackParam emcParam(*trackParam);
618  Float_t dPhiTemp = 0;
619  Float_t dEtaTemp = 0;
620 
621  if(cluster->IsEMCAL()){
622  Float_t eta = 0;Float_t phi = 0;Float_t pt = 0;
623  propagated = AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcParam, 430, 0.000510999, 20, eta, phi, pt);
624  if(propagated){
625  if( TMath::Abs(eta) > 0.8 ) {
626  delete trackParam;
627  fSecHistControlMatches->Fill(3.,inSecTrack->Pt());
628  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
629  return kFALSE;
630  }
631  // Save some time and memory in case of no DCal present
632  if( nModules < 13 && ( phi < 60*TMath::DegToRad() || phi > 200*TMath::DegToRad())){
633  delete trackParam;
634  fSecHistControlMatches->Fill(3.,inSecTrack->Pt());
635  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
636  return kFALSE;
637  }
638 
639  propagated = AliEMCALRecoUtils::ExtrapolateTrackToCluster(&emcParam, cluster, 0.000510999, 5, dEtaTemp, dPhiTemp);
640  if(!propagated){
641  delete trackParam;
642  fSecHistControlMatches->Fill(4.,inSecTrack->Pt());
643  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
644  return kFALSE;
645  }
646  }else{
647  delete trackParam;
648  fSecHistControlMatches->Fill(2.,inSecTrack->Pt());
649  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
650  return kFALSE;
651  }
652 
653  }else if(cluster->IsPHOS()){
654  propagated = AliTrackerBase::PropagateTrackToBxByBz(&emcParam, clusterR, 0.000510999, 20, kTRUE, 0.8, -1);
655  if (propagated){
656  Double_t trkPos[3] = {0,0,0};
657  emcParam.GetXYZ(trkPos);
658  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
659  TVector3 clsPosVec(clusterPosition);
660  dPhiTemp = clsPosVec.DeltaPhi(trkPosVec);
661  dEtaTemp = clsPosVec.Eta()-trkPosVec.Eta();
662  }else{
663  delete trackParam;
664  fSecHistControlMatches->Fill(2.,inSecTrack->Pt());
665  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
666  return kFALSE;}
667  }
668 
669  if (propagated){
670  Float_t dR2 = dPhiTemp*dPhiTemp + dEtaTemp*dEtaTemp;
671  //cout << dEtaTemp << " - " << dPhiTemp << " - " << dR2 << endl;
672  if(dR2 > fMatchingResidual){
673  fSecHistControlMatches->Fill(5.,inSecTrack->Pt());
674  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
675  //cout << "NO MATCH! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
676  delete trackParam;
677  return kFALSE;
678  }
679  //cout << "MATCHED!!!!!!!" << endl;
680 
681  if(aodev){
682  //need to search for position in case of AOD
683  Int_t TrackPos = -1;
684  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
685  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
686  if(currTrack->GetID() == inSecTrack->GetID()){
687  TrackPos = iTrack;
688  break;
689  }
690  }
691  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: PropagateV0TrackToClusterAndGetMatchingResidual - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",inSecTrack->GetID()));
692  fSecMapTrackToCluster.insert(make_pair(TrackPos,cluster->GetID()));
693  fSecMapClusterToTrack.insert(make_pair(cluster->GetID(),TrackPos));
694  }else{
695  fSecMapTrackToCluster.insert(make_pair(inSecTrack->GetID(),cluster->GetID()));
696  fSecMapClusterToTrack.insert(make_pair(cluster->GetID(),inSecTrack->GetID()));
697  }
698  fSecVectorDeltaEtaDeltaPhi.push_back(make_pair(dEtaTemp,dPhiTemp));
699  fSecMap_TrID_ClID_ToIndex[make_pair(inSecTrack->GetID(),cluster->GetID())] = fSecNEntries++;
700  if( (Int_t)fSecVectorDeltaEtaDeltaPhi.size() != (fSecNEntries-1)) AliFatal("Fatal error in AliCaloTrackMatcher, vector and map are not in sync!");
701 
702  fSecHistControlMatches->Fill(6.,inSecTrack->Pt());
703  dEta = dEtaTemp;
704  dPhi = dPhiTemp;
705  delete trackParam;
706  return kTRUE;
707  }else AliFatal("Fatal error in AliCaloTrackMatcher, track is labeled as sucessfully propagated although this should be impossible!");
708 
709  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
710  delete trackParam;
711  return kFALSE;
712 }
713 
714 //________________________________________________________________________
715 //________________________________________________________________________
716 //________________________________________________________________________
717 //________________________________________________________________________
718 //________________________________________________________________________
720  Int_t position = fMap_TrID_ClID_ToIndex[make_pair(trackID,clusterID)];
721  if(position == 0) return kFALSE;
722 
723  pairFloat tempEtaPhi = fVectorDeltaEtaDeltaPhi.at(position-1);
724  dEta = tempEtaPhi.first;
725  dPhi = tempEtaPhi.second;
726  return kTRUE;
727 }
728 //________________________________________________________________________
729 Int_t AliCaloTrackMatcher::GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
730  Int_t matched = 0;
731  multimap<Int_t,Int_t>::iterator it;
732  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
733  if(it->first == clusterID){
734  Float_t tempDEta, tempDPhi;
735  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
736  if(!tempTrack) continue;
737  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
738  if(tempTrack->Charge()>0){
739  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
740  }else if(tempTrack->Charge()<0){
741  dPhiMin*=-1;
742  dPhiMax*=-1;
743  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
744  }
745  }
746  }
747  }
748 
749  return matched;
750 }
751 
752 //________________________________________________________________________
753 Int_t AliCaloTrackMatcher::GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
754  Int_t matched = 0;
755  multimap<Int_t,Int_t>::iterator it;
756  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
757  if(it->first == clusterID){
758  Float_t tempDEta, tempDPhi;
759  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
760  if(!tempTrack) continue;
761  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
762  Bool_t match_dEta = kFALSE;
763  Bool_t match_dPhi = kFALSE;
764  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
765  else match_dEta = kFALSE;
766 
767  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
768  else match_dPhi = kFALSE;
769 
770  if (match_dPhi && match_dEta )matched++;
771  }
772  }
773  }
774  return matched;
775 }
776 
777 //________________________________________________________________________
779  Int_t matched = 0;
780  multimap<Int_t,Int_t>::iterator it;
781  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
782  if(it->first == clusterID){
783  Float_t tempDEta, tempDPhi;
784  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
785  if(!tempTrack) continue;
786  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
787  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
788  }
789  }
790  }
791  return matched;
792 }
793 
794 //________________________________________________________________________
795 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
796 
797  Int_t TrackPos = -1;
798  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
799  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
800  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
801  if(currTrack->GetID() == trackID){
802  TrackPos = iTrack;
803  break;
804  }
805  }
806  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
807  }else TrackPos = trackID; // for ESD just take trackID
808 
809  Int_t matched = 0;
810  multimap<Int_t,Int_t>::iterator it;
811  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
812  if(!tempTrack) return matched;
813  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
814  if(it->first == TrackPos){
815  Float_t tempDEta, tempDPhi;
816  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
817  if(tempTrack->Charge()>0){
818  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
819  }else if(tempTrack->Charge()<0){
820  dPhiMin*=-1;
821  dPhiMax*=-1;
822  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
823  }
824  }
825  }
826  }
827  return matched;
828 }
829 
830 //________________________________________________________________________
831 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
832  Int_t TrackPos = -1;
833  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
834  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
835  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
836  if(currTrack->GetID() == trackID){
837  TrackPos = iTrack;
838  break;
839  }
840  }
841  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
842  }else TrackPos = trackID; // for ESD just take trackID
843 
844  Int_t matched = 0;
845  multimap<Int_t,Int_t>::iterator it;
846  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
847  if(!tempTrack) return matched;
848  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
849  if(it->first == TrackPos){
850  Float_t tempDEta, tempDPhi;
851  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
852  Bool_t match_dEta = kFALSE;
853  Bool_t match_dPhi = kFALSE;
854  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
855  else match_dEta = kFALSE;
856 
857  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
858  else match_dPhi = kFALSE;
859 
860  if (match_dPhi && match_dEta )matched++;
861 
862  }
863  }
864  }
865  return matched;
866 }
867 
868 //________________________________________________________________________
870  Int_t TrackPos = -1;
871  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
872  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
873  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
874  if(currTrack->GetID() == trackID){
875  TrackPos = iTrack;
876  break;
877  }
878  }
879  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
880  }else TrackPos = trackID; // for ESD just take trackID
881 
882  Int_t matched = 0;
883  multimap<Int_t,Int_t>::iterator it;
884  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
885  if(!tempTrack) return matched;
886  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
887  if(it->first == TrackPos){
888  Float_t tempDEta, tempDPhi;
889  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
890  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
891  }
892  }
893  }
894  return matched;
895 }
896 
897 //________________________________________________________________________
898 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
899  vector<Int_t> tempMatchedTracks;
900  multimap<Int_t,Int_t>::iterator it;
901  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
902  if(it->first == clusterID){
903  Float_t tempDEta, tempDPhi;
904  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
905  if(!tempTrack) continue;
906  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
907  if(tempTrack->Charge()>0){
908  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedTracks.push_back(it->second);
909  }else if(tempTrack->Charge()<0){
910  dPhiMin*=-1;
911  dPhiMax*=-1;
912  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedTracks.push_back(it->second);
913  }
914  }
915  }
916  }
917  return tempMatchedTracks;
918 }
919 
920 //________________________________________________________________________
921 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
922  vector<Int_t> tempMatchedTracks;
923  multimap<Int_t,Int_t>::iterator it;
924  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
925  if(it->first == clusterID){
926  Float_t tempDEta, tempDPhi;
927  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
928  if(!tempTrack) continue;
929  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
930  Bool_t match_dEta = kFALSE;
931  Bool_t match_dPhi = kFALSE;
932  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
933  else match_dEta = kFALSE;
934 
935  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
936  else match_dPhi = kFALSE;
937 
938  if (match_dPhi && match_dEta )tempMatchedTracks.push_back(it->second);
939 
940  }
941  }
942  }
943  return tempMatchedTracks;
944 }
945 
946 //________________________________________________________________________
947 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dR){
948  vector<Int_t> tempMatchedTracks;
949  multimap<Int_t,Int_t>::iterator it;
950  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
951  if(it->first == clusterID){
952  Float_t tempDEta, tempDPhi;
953  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
954  if(!tempTrack) continue;
955  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
956  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedTracks.push_back(it->second);
957  }
958  }
959  }
960  return tempMatchedTracks;
961 }
962 
963 //________________________________________________________________________
964 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
965  Int_t TrackPos = -1;
966  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
967  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
968  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
969  if(currTrack->GetID() == trackID){
970  TrackPos = iTrack;
971  break;
972  }
973  }
974  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
975  }else TrackPos = trackID; // for ESD just take trackID
976 
977  vector<Int_t> tempMatchedClusters;
978  multimap<Int_t,Int_t>::iterator it;
979  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
980  if(!tempTrack) return tempMatchedClusters;
981  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
982  if(it->first == TrackPos){
983  Float_t tempDEta, tempDPhi;
984  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
985  if(tempTrack->Charge()>0){
986  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedClusters.push_back(it->second);
987  }else if(tempTrack->Charge()<0){
988  dPhiMin*=-1;
989  dPhiMax*=-1;
990  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedClusters.push_back(it->second);
991  }
992  }
993  }
994  }
995 
996  return tempMatchedClusters;
997 }
998 
999 //________________________________________________________________________
1000 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1001  Int_t TrackPos = -1;
1002  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1003  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1004  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1005  if(currTrack->GetID() == trackID){
1006  TrackPos = iTrack;
1007  break;
1008  }
1009  }
1010  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1011  }else TrackPos = trackID; // for ESD just take trackID
1012 
1013  vector<Int_t> tempMatchedClusters;
1014  multimap<Int_t,Int_t>::iterator it;
1015  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1016  if(!tempTrack) return tempMatchedClusters;
1017  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
1018  if(it->first == TrackPos){
1019  Float_t tempDEta, tempDPhi;
1020  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1021  Bool_t match_dEta = kFALSE;
1022  Bool_t match_dPhi = kFALSE;
1023  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1024  else match_dEta = kFALSE;
1025 
1026  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1027  else match_dPhi = kFALSE;
1028 
1029  if (match_dPhi && match_dEta )tempMatchedClusters.push_back(it->second);
1030  }
1031  }
1032  }
1033  return tempMatchedClusters;
1034 }
1035 
1036 //________________________________________________________________________
1037 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dR){
1038  Int_t TrackPos = -1;
1039  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1040  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1041  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1042  if(currTrack->GetID() == trackID){
1043  TrackPos = iTrack;
1044  break;
1045  }
1046  }
1047  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1048  }else TrackPos = trackID; // for ESD just take trackID
1049 
1050  vector<Int_t> tempMatchedClusters;
1051  multimap<Int_t,Int_t>::iterator it;
1052  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1053  if(!tempTrack) return tempMatchedClusters;
1054  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
1055  if(it->first == TrackPos){
1056  Float_t tempDEta, tempDPhi;
1057  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1058  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedClusters.push_back(it->second);
1059  }
1060  }
1061  }
1062  return tempMatchedClusters;
1063 }
1064 
1065 //________________________________________________________________________
1066 //________________________________________________________________________
1067 //________________________________________________________________________
1068 //________________________________________________________________________
1069 //________________________________________________________________________
1071  Int_t position = fSecMap_TrID_ClID_ToIndex[make_pair(trackID,clusterID)];
1072  if(position == 0) return kFALSE;
1073 
1074  pairFloat tempEtaPhi = fSecVectorDeltaEtaDeltaPhi.at(position-1);
1075  dEta = tempEtaPhi.first;
1076  dPhi = tempEtaPhi.second;
1077  return kTRUE;
1078 }
1079 //________________________________________________________________________
1081  Int_t position = fSecMap_TrID_ClID_AlreadyTried[make_pair(trackID,clusterID)];
1082  if(position == 0) return kFALSE;
1083  else return kTRUE;
1084 }
1085 //________________________________________________________________________
1086 Int_t AliCaloTrackMatcher::GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1087  Int_t matched = 0;
1088  multimap<Int_t,Int_t>::iterator it;
1089  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1090  if(it->first == clusterID){
1091  Float_t tempDEta, tempDPhi;
1092  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1093  if(!tempTrack) continue;
1094  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1095  if(tempTrack->Charge()>0){
1096  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
1097  }else if(tempTrack->Charge()<0){
1098  dPhiMin*=-1;
1099  dPhiMax*=-1;
1100  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
1101  }
1102  }
1103  }
1104  }
1105 
1106  return matched;
1107 }
1108 
1109 //________________________________________________________________________
1110 Int_t AliCaloTrackMatcher::GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1111  Int_t matched = 0;
1112  multimap<Int_t,Int_t>::iterator it;
1113  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1114  if(it->first == clusterID){
1115  Float_t tempDEta, tempDPhi;
1116  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1117  if(!tempTrack) continue;
1118  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1119  Bool_t match_dEta = kFALSE;
1120  Bool_t match_dPhi = kFALSE;
1121  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1122  else match_dEta = kFALSE;
1123 
1124  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1125  else match_dPhi = kFALSE;
1126 
1127  if (match_dPhi && match_dEta )matched++;
1128  }
1129  }
1130  }
1131 
1132  return matched;
1133 }
1134 
1135 //________________________________________________________________________
1137  Int_t matched = 0;
1138  multimap<Int_t,Int_t>::iterator it;
1139  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1140  if(it->first == clusterID){
1141  Float_t tempDEta, tempDPhi;
1142  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1143  if(!tempTrack) continue;
1144  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1145  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
1146  }
1147  }
1148  }
1149 
1150  return matched;
1151 }
1152 
1153 //________________________________________________________________________
1154 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1155  Int_t TrackPos = -1;
1156  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1157  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1158  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1159  if(currTrack->GetID() == trackID){
1160  TrackPos = iTrack;
1161  break;
1162  }
1163  }
1164  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1165  }else TrackPos = trackID; // for ESD just take trackID
1166 
1167  Int_t matched = 0;
1168  multimap<Int_t,Int_t>::iterator it;
1169  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1170  if(!tempTrack) return matched;
1171  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1172  if(it->first == TrackPos){
1173  Float_t tempDEta, tempDPhi;
1174  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1175  if(tempTrack->Charge()>0){
1176  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
1177  }else if(tempTrack->Charge()<0){
1178  dPhiMin*=-1;
1179  dPhiMax*=-1;
1180  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
1181  }
1182  }
1183  }
1184  }
1185 
1186  return matched;
1187 }
1188 
1189 //________________________________________________________________________
1190 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1191  Int_t TrackPos = -1;
1192  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1193  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1194  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1195  if(currTrack->GetID() == trackID){
1196  TrackPos = iTrack;
1197  break;
1198  }
1199  }
1200  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1201  }else TrackPos = trackID; // for ESD just take trackID
1202 
1203  Int_t matched = 0;
1204  multimap<Int_t,Int_t>::iterator it;
1205  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1206  if(!tempTrack) return matched;
1207  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1208  if(it->first == TrackPos){
1209  Float_t tempDEta, tempDPhi;
1210  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1211  Bool_t match_dEta = kFALSE;
1212  Bool_t match_dPhi = kFALSE;
1213  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1214  else match_dEta = kFALSE;
1215 
1216  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1217  else match_dPhi = kFALSE;
1218 
1219  if (match_dPhi && match_dEta )matched++;
1220 
1221  }
1222  }
1223  }
1224 
1225  return matched;
1226 }
1227 
1228 //________________________________________________________________________
1230  Int_t TrackPos = -1;
1231  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1232  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1233  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1234  if(currTrack->GetID() == trackID){
1235  TrackPos = iTrack;
1236  break;
1237  }
1238  }
1239  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1240  }else TrackPos = trackID; // for ESD just take trackID
1241 
1242  Int_t matched = 0;
1243  multimap<Int_t,Int_t>::iterator it;
1244  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1245  if(!tempTrack) return matched;
1246  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1247  if(it->first == TrackPos){
1248  Float_t tempDEta, tempDPhi;
1249  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1250  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
1251  }
1252  }
1253  }
1254 
1255  return matched;
1256 }
1257 
1258 //________________________________________________________________________
1259 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1260  vector<Int_t> tempMatchedTracks;
1261  multimap<Int_t,Int_t>::iterator it;
1262  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1263  if(it->first == clusterID){
1264  Float_t tempDEta, tempDPhi;
1265  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1266  if(!tempTrack) continue;
1267  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1268  if(tempTrack->Charge()>0){
1269  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedTracks.push_back(it->second);
1270  }else if(tempTrack->Charge()<0){
1271  dPhiMin*=-1;
1272  dPhiMax*=-1;
1273  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedTracks.push_back(it->second);
1274  }
1275  }
1276  }
1277  }
1278 
1279  return tempMatchedTracks;
1280 }
1281 
1282 //________________________________________________________________________
1283 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1284  vector<Int_t> tempMatchedTracks;
1285  multimap<Int_t,Int_t>::iterator it;
1286  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1287  if(it->first == clusterID){
1288  Float_t tempDEta, tempDPhi;
1289  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1290  if(!tempTrack) continue;
1291  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1292  Bool_t match_dEta = kFALSE;
1293  Bool_t match_dPhi = kFALSE;
1294  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1295  else match_dEta = kFALSE;
1296 
1297  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1298  else match_dPhi = kFALSE;
1299 
1300  if (match_dPhi && match_dEta )tempMatchedTracks.push_back(it->second);
1301  }
1302  }
1303  }
1304 
1305  return tempMatchedTracks;
1306 }
1307 
1308 //________________________________________________________________________
1309 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dR){
1310  vector<Int_t> tempMatchedTracks;
1311  multimap<Int_t,Int_t>::iterator it;
1312  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1313  if(it->first == clusterID){
1314  Float_t tempDEta, tempDPhi;
1315  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1316  if(!tempTrack) continue;
1317  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1318  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedTracks.push_back(it->second);
1319  }
1320  }
1321  }
1322 
1323  return tempMatchedTracks;
1324 }
1325 
1326 //________________________________________________________________________
1327 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1328  Int_t TrackPos = -1;
1329  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1330  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1331  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1332  if(currTrack->GetID() == trackID){
1333  TrackPos = iTrack;
1334  break;
1335  }
1336  }
1337  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1338  }else TrackPos = trackID; // for ESD just take trackID
1339 
1340  vector<Int_t> tempMatchedClusters;
1341  multimap<Int_t,Int_t>::iterator it;
1342  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1343  if(!tempTrack) return tempMatchedClusters;
1344  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1345  if(it->first == TrackPos){
1346  Float_t tempDEta, tempDPhi;
1347  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1348  if(tempTrack->Charge()>0){
1349  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedClusters.push_back(it->second);
1350  }else if(tempTrack->Charge()<0){
1351  dPhiMin*=-1;
1352  dPhiMax*=-1;
1353  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedClusters.push_back(it->second);
1354  }
1355  }
1356  }
1357  }
1358 
1359  return tempMatchedClusters;
1360 }
1361 
1362 //________________________________________________________________________
1363 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1364  Int_t TrackPos = -1;
1365  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1366  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1367  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1368  if(currTrack->GetID() == trackID){
1369  TrackPos = iTrack;
1370  break;
1371  }
1372  }
1373  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1374  }else TrackPos = trackID; // for ESD just take trackID
1375 
1376  vector<Int_t> tempMatchedClusters;
1377  multimap<Int_t,Int_t>::iterator it;
1378  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1379  if(!tempTrack) return tempMatchedClusters;
1380  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1381  if(it->first == TrackPos){
1382  Float_t tempDEta, tempDPhi;
1383  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1384  Bool_t match_dEta = kFALSE;
1385  Bool_t match_dPhi = kFALSE;
1386  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1387  else match_dEta = kFALSE;
1388 
1389  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1390  else match_dPhi = kFALSE;
1391 
1392  if (match_dPhi && match_dEta )tempMatchedClusters.push_back(it->second);
1393  }
1394  }
1395  }
1396 
1397  return tempMatchedClusters;
1398 }
1399 
1400 //________________________________________________________________________
1401 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dR){
1402  Int_t TrackPos = -1;
1403  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1404  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1405  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1406  if(currTrack->GetID() == trackID){
1407  TrackPos = iTrack;
1408  break;
1409  }
1410  }
1411  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1412  }else TrackPos = trackID; // for ESD just take trackID
1413 
1414  vector<Int_t> tempMatchedClusters;
1415  multimap<Int_t,Int_t>::iterator it;
1416  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1417  if(!tempTrack) return tempMatchedClusters;
1418  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1419  if(it->first == TrackPos){
1420  Float_t tempDEta, tempDPhi;
1421  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1422  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedClusters.push_back(it->second);
1423  }
1424  }
1425  }
1426 
1427  return tempMatchedClusters;
1428 }
1429 
1430 //________________________________________________________________________
1432  Float_t sumTrackEt = 0.;
1433  vector<Int_t> labelsMatched = GetMatchedTrackIDsForCluster(event, clusterID, dR);
1434  if((Int_t) labelsMatched.size()<1) return sumTrackEt;
1435 
1436  TLorentzVector vecTrack;
1437  for (UInt_t i = 0; i < labelsMatched.size(); i++){
1438  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(labelsMatched.at(i)));
1439  if(!currTrack) continue;
1440  vecTrack.SetPxPyPzE(currTrack->Px(),currTrack->Py(),currTrack->Pz(),currTrack->E());
1441  sumTrackEt += vecTrack.Et();
1442  }
1443 
1444  return sumTrackEt;
1445 }
1446 
1447 //________________________________________________________________________
1449  TAxis *axisafter = histoRebin->GetYaxis();
1450  Int_t bins = axisafter->GetNbins();
1451  Double_t from = axisafter->GetXmin();
1452  Double_t to = axisafter->GetXmax();
1453  Double_t *newbins = new Double_t[bins+1];
1454  newbins[0] = from;
1455  Double_t factor = TMath::Power(to/from, 1./bins);
1456  for(Int_t i=1; i<=bins; ++i) newbins[i] = factor * newbins[i-1];
1457  axisafter->Set(bins, newbins);
1458  delete [] newbins;
1459  return;
1460 }
1461 
1462 //________________________________________________________________________
1464  if(fSecVectorDeltaEtaDeltaPhi.size()>0){
1465  cout << "******************************" << endl;
1466  cout << "******************************" << endl;
1467  cout << "NEW EVENT !" << endl;
1468  cout << "vector etaphi:" << endl;
1469  cout << fSecVectorDeltaEtaDeltaPhi.size() << endl;
1470  cout << "multimap" << endl;
1471  mapT::iterator iter = fSecMap_TrID_ClID_ToIndex.begin();
1472  for (iter = fSecMap_TrID_ClID_ToIndex.begin(); iter != fSecMap_TrID_ClID_ToIndex.end(); ++iter){
1473  Float_t dEta, dPhi = 0;
1474  if(!GetSecTrackClusterMatchingResidual(iter->first.first,iter->first.second,dEta,dPhi)) continue;
1475  cout << " [" << iter->first.first << "/" << iter->first.second << ", " << iter->second << "] - (" << dEta << "/" << dPhi << ")" << endl;
1476  }
1477  cout << "mapTrackToCluster" << endl;
1478  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(fInputEvent);
1479  for (Int_t itr=0;itr<esdev->GetNumberOfTracks();itr++){
1480  AliVTrack *inTrack = esdev->GetTrack(itr);
1481  if(!inTrack) continue;
1482  TString tCharge;
1483  if(inTrack->Charge()>0) tCharge = "+";
1484  else if(inTrack->Charge()<0) tCharge = "-";
1485  cout << itr << " (" << tCharge << ") - " << GetNMatchedClusterIDsForSecTrack(fInputEvent,inTrack->GetID(),5,-5,0.2,-0.4) << "\t\t";
1486  }
1487  cout << endl;
1488  multimap<Int_t,Int_t>::iterator it;
1489  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it) cout << it->first << " => " << it->second << '\n';
1490  cout << "mapClusterToTrack" << endl;
1491  Int_t tempClus = it->second;
1492  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it) cout << it->first << " => " << it->second << '\n';
1493  vector<Int_t> tempTracks = GetMatchedSecTrackIDsForCluster(fInputEvent,tempClus, 5, -5, 0.2, -0.4);
1494  for(UInt_t iJ=0; iJ<tempTracks.size();iJ++){
1495  cout << tempClus << " - " << tempTracks.at(iJ) << endl;
1496  }
1497  }
1498  return;
1499 }
1500 
1501 //________________________________________________________________________
1503  if(fVectorDeltaEtaDeltaPhi.size()>0){
1504  cout << "******************************" << endl;
1505  cout << "******************************" << endl;
1506  cout << "NEW EVENT !" << endl;
1507  cout << "vector etaphi:" << endl;
1508  cout << fVectorDeltaEtaDeltaPhi.size() << endl;
1509  cout << "multimap" << endl;
1510  mapT::iterator iter = fMap_TrID_ClID_ToIndex.begin();
1511  for (iter = fMap_TrID_ClID_ToIndex.begin(); iter != fMap_TrID_ClID_ToIndex.end(); ++iter){
1512  Float_t dEta, dPhi = 0;
1513  if(!GetTrackClusterMatchingResidual(iter->first.first,iter->first.second,dEta,dPhi)) continue;
1514  cout << " [" << iter->first.first << "/" << iter->first.second << ", " << iter->second << "] - (" << dEta << "/" << dPhi << ")" << endl;
1515  }
1516  cout << "mapTrackToCluster" << endl;
1517  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(fInputEvent);
1518  for (Int_t itr=0;itr<esdev->GetNumberOfTracks();itr++){
1519  AliVTrack *inTrack = esdev->GetTrack(itr);
1520  if(!inTrack) continue;
1521  TString tCharge;
1522  if(inTrack->Charge()>0) tCharge = "+";
1523  else if(inTrack->Charge()<0) tCharge = "-";
1524  cout << itr << " (" << tCharge << ") - " << GetNMatchedClusterIDsForTrack(fInputEvent,inTrack->GetID(),5,-5,0.2,-0.4) << "\t\t";
1525  }
1526  cout << endl;
1527  multimap<Int_t,Int_t>::iterator it;
1528  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it) cout << it->first << " => " << it->second << '\n';
1529  cout << "mapClusterToTrack" << endl;
1530  Int_t tempClus = it->second;
1531  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it) cout << it->first << " => " << it->second << '\n';
1532  vector<Int_t> tempTracks = GetMatchedTrackIDsForCluster(fInputEvent,tempClus, 5, -5, 0.2, -0.4);
1533  for(UInt_t iJ=0; iJ<tempTracks.size();iJ++){
1534  cout << tempClus << " - " << tempTracks.at(iJ) << endl;
1535  }
1536  }
1537  return;
1538 }
double Double_t
Definition: External.C:58
Definition: External.C:236
Int_t GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
void ProcessEvent(AliVEvent *event)
Bool_t GetTrackClusterMatchingResidual(Int_t trackID, Int_t clusterID, Float_t &dEta, Float_t &dPhi)
void Initialize(Int_t runNumber)
vector< Int_t > GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
Int_t GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
virtual void Terminate(Option_t *)
Bool_t GetSecTrackClusterMatchingResidual(Int_t trackID, Int_t clusterID, Float_t &dEta, Float_t &dPhi)
Float_t SumTrackEtAroundCluster(AliVEvent *event, Int_t clusterID, Float_t dR)
Int_t GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
vector< Int_t > GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
virtual void UserExec(Option_t *option)
static Bool_t ExtrapolateTrackToCluster(AliExternalTrackParam *trkParam, const AliVCluster *cluster, Double_t mass, Double_t step, Float_t &tmpEta, Float_t &tmpPhi)
Definition: External.C:220
Int_t GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
Bool_t PropagateV0TrackToClusterAndGetMatchingResidual(AliVTrack *inSecTrack, AliVCluster *cluster, AliVEvent *event, Float_t &dEta, Float_t &dPhi)
pair< Float_t, Float_t > pairFloat
Bool_t IsSecTrackClusterAlreadyTried(Int_t trackID, Int_t clusterID)
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
vector< Int_t > GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1 *fFuncPtDepEta, TF1 *fFuncPtDepPhi)
vector< Int_t > GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
void SetLogBinningYTH2(TH2 *histoRebin)