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