AliPhysics  2c6b7ad (2c6b7ad)
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  Double_t trkPos[3] = {0,0,0};
395  if(emcParam.GetXYZ(trkPos)){
396  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
397  if (TMath::Abs(trkPosVec.Eta()) > 0.25 && (fClusterType == 2)){
398  delete trackParam;
399  fHistControlMatches->Fill(3.,inTrack->Pt());
400  continue;
401  }
402  }
403  }
404 
405  Float_t dEta=-999, dPhi=-999;
406  Float_t clsPos[3] = {0.,0.,0.};
407  Double_t exPos[3] = {0.,0.,0.};
408  if (!emcParam.GetXYZ(exPos)){
409  delete trackParam;
410  fHistControlMatches->Fill(2.,inTrack->Pt());
411  continue;
412  }
413 
414  // cout << inTrack->GetID() << " - " << trackParam << endl;
415  // cout << "eta/phi: " << eta << ", " << phi << endl;
416  // cout << "nClus: " << nClus << endl;
417  Int_t nClusterMatchesToTrack = 0;
418  for(Int_t iclus=0;iclus < nClus;iclus++){
419  AliVCluster* cluster = NULL;
420  if(arrClusters){
421  if(esdev){
422  if(arrClusters)
423  cluster = new AliESDCaloCluster(*(AliESDCaloCluster*)arrClusters->At(iclus));
424  } else if(aodev){
425  if(arrClusters)
426  cluster = new AliAODCaloCluster(*(AliAODCaloCluster*)arrClusters->At(iclus));
427  }
428  }
429  else
430  cluster = event->GetCaloCluster(iclus);
431  if (!cluster){
432  if(arrClusters) delete cluster;
433  continue;
434  }
435  // cout << "-------------------------LOOPING: " << iclus << ", " << cluster->GetID() << endl;
436  cluster->GetPosition(clsPos);
437  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));
438  //cout << "dR: " << dR << endl;
439  if (dR > fMatchingWindow){
440  if(arrClusters) delete cluster;
441  continue;
442  }
443  Double_t clusterR = TMath::Sqrt( clsPos[0]*clsPos[0] + clsPos[1]*clsPos[1] );
444  AliExternalTrackParam trackParamTmp(emcParam);//Retrieve the starting point every time before the extrapolation
445  if(fClusterType == 1 || fClusterType == 3){
446  if (!cluster->IsEMCAL()){
447  if(arrClusters) delete cluster;
448  continue;
449  }
450  if(!AliEMCALRecoUtils::ExtrapolateTrackToCluster(&trackParamTmp, cluster, 0.139, 5., dEta, dPhi)){
451  fHistControlMatches->Fill(4.,inTrack->Pt());
452  if(arrClusters) delete cluster;
453  continue;
454  }
455  }else if(fClusterType == 2){
456  if (!cluster->IsPHOS()){
457  if(arrClusters) delete cluster;
458  continue;
459  }
460  if(!AliTrackerBase::PropagateTrackToBxByBz(&trackParamTmp, clusterR, 0.139, 5., kTRUE, 0.8, -1)){
461  fHistControlMatches->Fill(4.,inTrack->Pt());
462  if(arrClusters) delete cluster;
463  continue;
464  }
465  Double_t trkPos[3] = {0,0,0};
466  trackParamTmp.GetXYZ(trkPos);
467  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
468  TVector3 clsPosVec(clsPos);
469  dPhi = clsPosVec.DeltaPhi(trkPosVec);
470  dEta = clsPosVec.Eta()-trkPosVec.Eta();
471  }
472 
473  Float_t dR2 = dPhi*dPhi + dEta*dEta;
474 
475  //cout << dEta << " - " << dPhi << " - " << dR2 << endl;
476  if(dR2 > fMatchingResidual){
477  if(arrClusters) delete cluster;
478  continue;
479  }
480  nClusterMatchesToTrack++;
481  if(aodev){
482  fMapTrackToCluster.insert(make_pair(itr,cluster->GetID()));
483  fMapClusterToTrack.insert(make_pair(cluster->GetID(),itr));
484  }else{
485  fMapTrackToCluster.insert(make_pair(inTrack->GetID(),cluster->GetID()));
486  fMapClusterToTrack.insert(make_pair(cluster->GetID(),inTrack->GetID()));
487  }
488  fVectorDeltaEtaDeltaPhi.push_back(make_pair(dEta,dPhi));
489  fMap_TrID_ClID_ToIndex[make_pair(inTrack->GetID(),cluster->GetID())] = fNEntries++;
490  if( (Int_t)fVectorDeltaEtaDeltaPhi.size() != (fNEntries-1)) AliFatal("Fatal error in AliCaloTrackMatcher, vector and map are not in sync!");
491  if(arrClusters) delete cluster;
492  }
493  if(nClusterMatchesToTrack == 0) fHistControlMatches->Fill(5.,inTrack->Pt());
494  else fHistControlMatches->Fill(6.,inTrack->Pt());
495  delete trackParam;
496  }
497 
498  return;
499 }
500 
501 //________________________________________________________________________
502 Bool_t AliCaloTrackMatcher::PropagateV0TrackToClusterAndGetMatchingResidual(AliVTrack* inSecTrack, AliVCluster* cluster, AliVEvent* event, Float_t &dEta, Float_t &dPhi){
503 
504  //if V0-track to cluster match is already available return stored residuals
505  if(GetSecTrackClusterMatchingResidual(inSecTrack->GetID(),cluster->GetID(), dEta, dPhi)){
506  //cout << "RESIDUAL ALREADY AVAILABLE! - " << dEta << "/" << dPhi << endl;
507  return kTRUE;
508  }
509 
510  if(IsSecTrackClusterAlreadyTried(inSecTrack->GetID(),cluster->GetID())){
511  //cout << "PROPAGATION ALREADY FAILED! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
512  return kFALSE;
513  }
514 
515  //cout << "running matching! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
516  //if match has not yet been computed, go on:
517  Int_t nModules = 0;
518  if(fClusterType == 1 || fClusterType == 3) nModules = fGeomEMCAL->GetNumberOfSuperModules();
519  else if(fClusterType == 2) nModules = fGeomPHOS->GetNModules();
520 
521  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(event);
522  AliAODEvent *aodev = 0;
523  if (!esdev) {
524  aodev = dynamic_cast<AliAODEvent*>(event);
525  if (!aodev) {
526  AliError("Task needs AOD or ESD event, returning");
527  return kFALSE;
528  }
529  }
530 
531  if(!cluster->IsEMCAL() && !cluster->IsPHOS()){AliError("Cluster is neither EMCAL nor PHOS, returning");return kFALSE;}
532 
533  Float_t clusterPosition[3] = {0,0,0};
534  cluster->GetPosition(clusterPosition);
535  Double_t clusterR = TMath::Sqrt( clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1] );
536 
537  if(!inSecTrack) return kFALSE;
538  fSecHistControlMatches->Fill(0.,inSecTrack->Pt());
539 
540  if (inSecTrack->Pt() < 0.3 ) {
541  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
542  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
543  return kFALSE;
544  }
545 
546  AliESDtrack *esdt = dynamic_cast<AliESDtrack*>(inSecTrack);
547  AliAODTrack *aodt = 0;
548  if (!esdt) {
549  aodt = dynamic_cast<AliAODTrack*>(inSecTrack);
550  if (!aodt){
551  AliError("Track is neither ESD nor AOD, continue");
552  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
553  return kFALSE;
554  }
555  }
556 
557  AliExternalTrackParam *trackParam = 0;
558  if (esdt) {
559  const AliExternalTrackParam *in = esdt->GetInnerParam();
560  if (!in){
561  AliDebug(2, "Could not get InnerParam of Track, continue");
562  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
563  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
564  return kFALSE;
565  }
566  trackParam = new AliExternalTrackParam(*in);
567  } else {
568  // check if tracks should be propagated at all
569  if (fClusterType == 1 || fClusterType == 3){
570  if (TMath::Abs(aodt->GetTrackEtaOnEMCal()) > 0.8){
571  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
572  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
573  return kFALSE;
574  }
575  if( nModules < 13 ){
576  if (( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())){
577  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
578  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
579  return kFALSE;
580  }
581  } else if( nModules > 12 ){
582  if (fClusterType == 3 && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad())){
583  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
584  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
585  return kFALSE;
586  }
587  if( fClusterType == 1 && ( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())){
588  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
589  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
590  return kFALSE;
591  }
592  }
593  } else {
594  if ( aodt->Phi() < 60*TMath::DegToRad() || aodt->Phi() > 200*TMath::DegToRad()){
595  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
596  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
597  return kFALSE;
598  }
599  if (TMath::Abs(aodt->Eta()) > 0.3 ){
600  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
601  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
602  return kFALSE;
603  }
604  }
605 
606  Double_t xyz[3] = {0}, pxpypz[3] = {0}, cv[21] = {0};
607  aodt->GetPxPyPz(pxpypz);
608  aodt->GetXYZ(xyz);
609  aodt->GetCovarianceXYZPxPyPz(cv);
610  trackParam = new AliExternalTrackParam(xyz,pxpypz,cv,aodt->Charge());
611  }
612  if(!trackParam){
613  AliError("Could not get TrackParameters, continue");
614  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
615  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
616  return kFALSE;
617  }
618 
619  Bool_t propagated = kFALSE;
620  AliExternalTrackParam emcParam(*trackParam);
621  Float_t dPhiTemp = 0;
622  Float_t dEtaTemp = 0;
623 
624  if(cluster->IsEMCAL()){
625  Float_t eta = 0;Float_t phi = 0;Float_t pt = 0;
626  propagated = AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcParam, 430, 0.000510999, 20, eta, phi, pt);
627  if(propagated){
628  if( TMath::Abs(eta) > 0.8 ) {
629  delete trackParam;
630  fSecHistControlMatches->Fill(3.,inSecTrack->Pt());
631  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
632  return kFALSE;
633  }
634  // Save some time and memory in case of no DCal present
635  if( nModules < 13 && ( phi < 60*TMath::DegToRad() || phi > 200*TMath::DegToRad())){
636  delete trackParam;
637  fSecHistControlMatches->Fill(3.,inSecTrack->Pt());
638  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
639  return kFALSE;
640  }
641 
642  propagated = AliEMCALRecoUtils::ExtrapolateTrackToCluster(&emcParam, cluster, 0.000510999, 5, dEtaTemp, dPhiTemp);
643  if(!propagated){
644  delete trackParam;
645  fSecHistControlMatches->Fill(4.,inSecTrack->Pt());
646  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
647  return kFALSE;
648  }
649  }else{
650  delete trackParam;
651  fSecHistControlMatches->Fill(2.,inSecTrack->Pt());
652  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
653  return kFALSE;
654  }
655 
656  }else if(cluster->IsPHOS()){
657  propagated = AliTrackerBase::PropagateTrackToBxByBz(&emcParam, clusterR, 0.000510999, 20, kTRUE, 0.8, -1);
658  if (propagated){
659  Double_t trkPos[3] = {0,0,0};
660  emcParam.GetXYZ(trkPos);
661  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
662  TVector3 clsPosVec(clusterPosition);
663  dPhiTemp = clsPosVec.DeltaPhi(trkPosVec);
664  dEtaTemp = clsPosVec.Eta()-trkPosVec.Eta();
665  }else{
666  delete trackParam;
667  fSecHistControlMatches->Fill(2.,inSecTrack->Pt());
668  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
669  return kFALSE;}
670  }
671 
672  if (propagated){
673  Float_t dR2 = dPhiTemp*dPhiTemp + dEtaTemp*dEtaTemp;
674  //cout << dEtaTemp << " - " << dPhiTemp << " - " << dR2 << endl;
675  if(dR2 > fMatchingResidual){
676  fSecHistControlMatches->Fill(5.,inSecTrack->Pt());
677  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
678  //cout << "NO MATCH! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
679  delete trackParam;
680  return kFALSE;
681  }
682  //cout << "MATCHED!!!!!!!" << endl;
683 
684  if(aodev){
685  //need to search for position in case of AOD
686  Int_t TrackPos = -1;
687  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
688  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
689  if(currTrack->GetID() == inSecTrack->GetID()){
690  TrackPos = iTrack;
691  break;
692  }
693  }
694  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()));
695  fSecMapTrackToCluster.insert(make_pair(TrackPos,cluster->GetID()));
696  fSecMapClusterToTrack.insert(make_pair(cluster->GetID(),TrackPos));
697  }else{
698  fSecMapTrackToCluster.insert(make_pair(inSecTrack->GetID(),cluster->GetID()));
699  fSecMapClusterToTrack.insert(make_pair(cluster->GetID(),inSecTrack->GetID()));
700  }
701  fSecVectorDeltaEtaDeltaPhi.push_back(make_pair(dEtaTemp,dPhiTemp));
702  fSecMap_TrID_ClID_ToIndex[make_pair(inSecTrack->GetID(),cluster->GetID())] = fSecNEntries++;
703  if( (Int_t)fSecVectorDeltaEtaDeltaPhi.size() != (fSecNEntries-1)) AliFatal("Fatal error in AliCaloTrackMatcher, vector and map are not in sync!");
704 
705  fSecHistControlMatches->Fill(6.,inSecTrack->Pt());
706  dEta = dEtaTemp;
707  dPhi = dPhiTemp;
708  delete trackParam;
709  return kTRUE;
710  }else AliFatal("Fatal error in AliCaloTrackMatcher, track is labeled as sucessfully propagated although this should be impossible!");
711 
712  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
713  delete trackParam;
714  return kFALSE;
715 }
716 
717 //________________________________________________________________________
718 //________________________________________________________________________
719 //________________________________________________________________________
720 //________________________________________________________________________
721 //________________________________________________________________________
723  Int_t position = fMap_TrID_ClID_ToIndex[make_pair(trackID,clusterID)];
724  if(position == 0) return kFALSE;
725 
726  pairFloat tempEtaPhi = fVectorDeltaEtaDeltaPhi.at(position-1);
727  dEta = tempEtaPhi.first;
728  dPhi = tempEtaPhi.second;
729  return kTRUE;
730 }
731 //________________________________________________________________________
732 Int_t AliCaloTrackMatcher::GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
733  Int_t matched = 0;
734  multimap<Int_t,Int_t>::iterator it;
735  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
736  if(it->first == clusterID){
737  Float_t tempDEta, tempDPhi;
738  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
739  if(!tempTrack) continue;
740  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
741  if(tempTrack->Charge()>0){
742  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
743  }else if(tempTrack->Charge()<0){
744  dPhiMin*=-1;
745  dPhiMax*=-1;
746  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
747  }
748  }
749  }
750  }
751 
752  return matched;
753 }
754 
755 //________________________________________________________________________
756 Int_t AliCaloTrackMatcher::GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
757  Int_t matched = 0;
758  multimap<Int_t,Int_t>::iterator it;
759  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
760  if(it->first == clusterID){
761  Float_t tempDEta, tempDPhi;
762  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
763  if(!tempTrack) continue;
764  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
765  Bool_t match_dEta = kFALSE;
766  Bool_t match_dPhi = kFALSE;
767  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
768  else match_dEta = kFALSE;
769 
770  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
771  else match_dPhi = kFALSE;
772 
773  if (match_dPhi && match_dEta )matched++;
774  }
775  }
776  }
777  return matched;
778 }
779 
780 //________________________________________________________________________
782  Int_t matched = 0;
783  multimap<Int_t,Int_t>::iterator it;
784  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
785  if(it->first == clusterID){
786  Float_t tempDEta, tempDPhi;
787  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
788  if(!tempTrack) continue;
789  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
790  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
791  }
792  }
793  }
794  return matched;
795 }
796 
797 //________________________________________________________________________
798 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
799 
800  Int_t TrackPos = -1;
801  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
802  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
803  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
804  if(currTrack->GetID() == trackID){
805  TrackPos = iTrack;
806  break;
807  }
808  }
809  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));
810  }else TrackPos = trackID; // for ESD just take trackID
811 
812  Int_t matched = 0;
813  multimap<Int_t,Int_t>::iterator it;
814  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
815  if(!tempTrack) return matched;
816  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
817  if(it->first == TrackPos){
818  Float_t tempDEta, tempDPhi;
819  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
820  if(tempTrack->Charge()>0){
821  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
822  }else if(tempTrack->Charge()<0){
823  dPhiMin*=-1;
824  dPhiMax*=-1;
825  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
826  }
827  }
828  }
829  }
830  return matched;
831 }
832 
833 //________________________________________________________________________
834 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
835  Int_t TrackPos = -1;
836  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
837  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
838  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
839  if(currTrack->GetID() == trackID){
840  TrackPos = iTrack;
841  break;
842  }
843  }
844  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));
845  }else TrackPos = trackID; // for ESD just take trackID
846 
847  Int_t matched = 0;
848  multimap<Int_t,Int_t>::iterator it;
849  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
850  if(!tempTrack) return matched;
851  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
852  if(it->first == TrackPos){
853  Float_t tempDEta, tempDPhi;
854  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
855  Bool_t match_dEta = kFALSE;
856  Bool_t match_dPhi = kFALSE;
857  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
858  else match_dEta = kFALSE;
859 
860  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
861  else match_dPhi = kFALSE;
862 
863  if (match_dPhi && match_dEta )matched++;
864 
865  }
866  }
867  }
868  return matched;
869 }
870 
871 //________________________________________________________________________
873  Int_t TrackPos = -1;
874  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
875  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
876  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
877  if(currTrack->GetID() == trackID){
878  TrackPos = iTrack;
879  break;
880  }
881  }
882  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));
883  }else TrackPos = trackID; // for ESD just take trackID
884 
885  Int_t matched = 0;
886  multimap<Int_t,Int_t>::iterator it;
887  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
888  if(!tempTrack) return matched;
889  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
890  if(it->first == TrackPos){
891  Float_t tempDEta, tempDPhi;
892  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
893  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
894  }
895  }
896  }
897  return matched;
898 }
899 
900 //________________________________________________________________________
901 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
902  vector<Int_t> tempMatchedTracks;
903  multimap<Int_t,Int_t>::iterator it;
904  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
905  if(it->first == clusterID){
906  Float_t tempDEta, tempDPhi;
907  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
908  if(!tempTrack) continue;
909  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
910  if(tempTrack->Charge()>0){
911  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedTracks.push_back(it->second);
912  }else if(tempTrack->Charge()<0){
913  dPhiMin*=-1;
914  dPhiMax*=-1;
915  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedTracks.push_back(it->second);
916  }
917  }
918  }
919  }
920  return tempMatchedTracks;
921 }
922 
923 //________________________________________________________________________
924 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
925  vector<Int_t> tempMatchedTracks;
926  multimap<Int_t,Int_t>::iterator it;
927  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
928  if(it->first == clusterID){
929  Float_t tempDEta, tempDPhi;
930  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
931  if(!tempTrack) continue;
932  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
933  Bool_t match_dEta = kFALSE;
934  Bool_t match_dPhi = kFALSE;
935  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
936  else match_dEta = kFALSE;
937 
938  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
939  else match_dPhi = kFALSE;
940 
941  if (match_dPhi && match_dEta )tempMatchedTracks.push_back(it->second);
942 
943  }
944  }
945  }
946  return tempMatchedTracks;
947 }
948 
949 //________________________________________________________________________
950 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dR){
951  vector<Int_t> tempMatchedTracks;
952  multimap<Int_t,Int_t>::iterator it;
953  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
954  if(it->first == clusterID){
955  Float_t tempDEta, tempDPhi;
956  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
957  if(!tempTrack) continue;
958  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
959  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedTracks.push_back(it->second);
960  }
961  }
962  }
963  return tempMatchedTracks;
964 }
965 
966 //________________________________________________________________________
967 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
968  Int_t TrackPos = -1;
969  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
970  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
971  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
972  if(currTrack->GetID() == trackID){
973  TrackPos = iTrack;
974  break;
975  }
976  }
977  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));
978  }else TrackPos = trackID; // for ESD just take trackID
979 
980  vector<Int_t> tempMatchedClusters;
981  multimap<Int_t,Int_t>::iterator it;
982  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
983  if(!tempTrack) return tempMatchedClusters;
984  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
985  if(it->first == TrackPos){
986  Float_t tempDEta, tempDPhi;
987  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
988  if(tempTrack->Charge()>0){
989  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedClusters.push_back(it->second);
990  }else if(tempTrack->Charge()<0){
991  dPhiMin*=-1;
992  dPhiMax*=-1;
993  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedClusters.push_back(it->second);
994  }
995  }
996  }
997  }
998 
999  return tempMatchedClusters;
1000 }
1001 
1002 //________________________________________________________________________
1003 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1004  Int_t TrackPos = -1;
1005  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1006  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1007  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1008  if(currTrack->GetID() == trackID){
1009  TrackPos = iTrack;
1010  break;
1011  }
1012  }
1013  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));
1014  }else TrackPos = trackID; // for ESD just take trackID
1015 
1016  vector<Int_t> tempMatchedClusters;
1017  multimap<Int_t,Int_t>::iterator it;
1018  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1019  if(!tempTrack) return tempMatchedClusters;
1020  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
1021  if(it->first == TrackPos){
1022  Float_t tempDEta, tempDPhi;
1023  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1024  Bool_t match_dEta = kFALSE;
1025  Bool_t match_dPhi = kFALSE;
1026  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1027  else match_dEta = kFALSE;
1028 
1029  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1030  else match_dPhi = kFALSE;
1031 
1032  if (match_dPhi && match_dEta )tempMatchedClusters.push_back(it->second);
1033  }
1034  }
1035  }
1036  return tempMatchedClusters;
1037 }
1038 
1039 //________________________________________________________________________
1040 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dR){
1041  Int_t TrackPos = -1;
1042  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1043  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1044  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1045  if(currTrack->GetID() == trackID){
1046  TrackPos = iTrack;
1047  break;
1048  }
1049  }
1050  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));
1051  }else TrackPos = trackID; // for ESD just take trackID
1052 
1053  vector<Int_t> tempMatchedClusters;
1054  multimap<Int_t,Int_t>::iterator it;
1055  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1056  if(!tempTrack) return tempMatchedClusters;
1057  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
1058  if(it->first == TrackPos){
1059  Float_t tempDEta, tempDPhi;
1060  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1061  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedClusters.push_back(it->second);
1062  }
1063  }
1064  }
1065  return tempMatchedClusters;
1066 }
1067 
1068 //________________________________________________________________________
1069 //________________________________________________________________________
1070 //________________________________________________________________________
1071 //________________________________________________________________________
1072 //________________________________________________________________________
1074  Int_t position = fSecMap_TrID_ClID_ToIndex[make_pair(trackID,clusterID)];
1075  if(position == 0) return kFALSE;
1076 
1077  pairFloat tempEtaPhi = fSecVectorDeltaEtaDeltaPhi.at(position-1);
1078  dEta = tempEtaPhi.first;
1079  dPhi = tempEtaPhi.second;
1080  return kTRUE;
1081 }
1082 //________________________________________________________________________
1084  Int_t position = fSecMap_TrID_ClID_AlreadyTried[make_pair(trackID,clusterID)];
1085  if(position == 0) return kFALSE;
1086  else return kTRUE;
1087 }
1088 //________________________________________________________________________
1089 Int_t AliCaloTrackMatcher::GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1090  Int_t matched = 0;
1091  multimap<Int_t,Int_t>::iterator it;
1092  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1093  if(it->first == clusterID){
1094  Float_t tempDEta, tempDPhi;
1095  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1096  if(!tempTrack) continue;
1097  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1098  if(tempTrack->Charge()>0){
1099  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
1100  }else if(tempTrack->Charge()<0){
1101  dPhiMin*=-1;
1102  dPhiMax*=-1;
1103  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
1104  }
1105  }
1106  }
1107  }
1108 
1109  return matched;
1110 }
1111 
1112 //________________________________________________________________________
1113 Int_t AliCaloTrackMatcher::GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1114  Int_t matched = 0;
1115  multimap<Int_t,Int_t>::iterator it;
1116  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1117  if(it->first == clusterID){
1118  Float_t tempDEta, tempDPhi;
1119  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1120  if(!tempTrack) continue;
1121  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1122  Bool_t match_dEta = kFALSE;
1123  Bool_t match_dPhi = kFALSE;
1124  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1125  else match_dEta = kFALSE;
1126 
1127  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1128  else match_dPhi = kFALSE;
1129 
1130  if (match_dPhi && match_dEta )matched++;
1131  }
1132  }
1133  }
1134 
1135  return matched;
1136 }
1137 
1138 //________________________________________________________________________
1140  Int_t matched = 0;
1141  multimap<Int_t,Int_t>::iterator it;
1142  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1143  if(it->first == clusterID){
1144  Float_t tempDEta, tempDPhi;
1145  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1146  if(!tempTrack) continue;
1147  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1148  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
1149  }
1150  }
1151  }
1152 
1153  return matched;
1154 }
1155 
1156 //________________________________________________________________________
1157 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1158  Int_t TrackPos = -1;
1159  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1160  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1161  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1162  if(currTrack->GetID() == trackID){
1163  TrackPos = iTrack;
1164  break;
1165  }
1166  }
1167  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));
1168  }else TrackPos = trackID; // for ESD just take trackID
1169 
1170  Int_t matched = 0;
1171  multimap<Int_t,Int_t>::iterator it;
1172  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1173  if(!tempTrack) return matched;
1174  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1175  if(it->first == TrackPos){
1176  Float_t tempDEta, tempDPhi;
1177  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1178  if(tempTrack->Charge()>0){
1179  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
1180  }else if(tempTrack->Charge()<0){
1181  dPhiMin*=-1;
1182  dPhiMax*=-1;
1183  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
1184  }
1185  }
1186  }
1187  }
1188 
1189  return matched;
1190 }
1191 
1192 //________________________________________________________________________
1193 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1194  Int_t TrackPos = -1;
1195  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1196  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1197  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1198  if(currTrack->GetID() == trackID){
1199  TrackPos = iTrack;
1200  break;
1201  }
1202  }
1203  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));
1204  }else TrackPos = trackID; // for ESD just take trackID
1205 
1206  Int_t matched = 0;
1207  multimap<Int_t,Int_t>::iterator it;
1208  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1209  if(!tempTrack) return matched;
1210  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1211  if(it->first == TrackPos){
1212  Float_t tempDEta, tempDPhi;
1213  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1214  Bool_t match_dEta = kFALSE;
1215  Bool_t match_dPhi = kFALSE;
1216  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1217  else match_dEta = kFALSE;
1218 
1219  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1220  else match_dPhi = kFALSE;
1221 
1222  if (match_dPhi && match_dEta )matched++;
1223 
1224  }
1225  }
1226  }
1227 
1228  return matched;
1229 }
1230 
1231 //________________________________________________________________________
1233  Int_t TrackPos = -1;
1234  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1235  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1236  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1237  if(currTrack->GetID() == trackID){
1238  TrackPos = iTrack;
1239  break;
1240  }
1241  }
1242  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));
1243  }else TrackPos = trackID; // for ESD just take trackID
1244 
1245  Int_t matched = 0;
1246  multimap<Int_t,Int_t>::iterator it;
1247  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1248  if(!tempTrack) return matched;
1249  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1250  if(it->first == TrackPos){
1251  Float_t tempDEta, tempDPhi;
1252  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1253  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
1254  }
1255  }
1256  }
1257 
1258  return matched;
1259 }
1260 
1261 //________________________________________________________________________
1262 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1263  vector<Int_t> tempMatchedTracks;
1264  multimap<Int_t,Int_t>::iterator it;
1265  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1266  if(it->first == clusterID){
1267  Float_t tempDEta, tempDPhi;
1268  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1269  if(!tempTrack) continue;
1270  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1271  if(tempTrack->Charge()>0){
1272  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedTracks.push_back(it->second);
1273  }else if(tempTrack->Charge()<0){
1274  dPhiMin*=-1;
1275  dPhiMax*=-1;
1276  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedTracks.push_back(it->second);
1277  }
1278  }
1279  }
1280  }
1281 
1282  return tempMatchedTracks;
1283 }
1284 
1285 //________________________________________________________________________
1286 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1287  vector<Int_t> tempMatchedTracks;
1288  multimap<Int_t,Int_t>::iterator it;
1289  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1290  if(it->first == clusterID){
1291  Float_t tempDEta, tempDPhi;
1292  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1293  if(!tempTrack) continue;
1294  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1295  Bool_t match_dEta = kFALSE;
1296  Bool_t match_dPhi = kFALSE;
1297  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1298  else match_dEta = kFALSE;
1299 
1300  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1301  else match_dPhi = kFALSE;
1302 
1303  if (match_dPhi && match_dEta )tempMatchedTracks.push_back(it->second);
1304  }
1305  }
1306  }
1307 
1308  return tempMatchedTracks;
1309 }
1310 
1311 //________________________________________________________________________
1312 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dR){
1313  vector<Int_t> tempMatchedTracks;
1314  multimap<Int_t,Int_t>::iterator it;
1315  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1316  if(it->first == clusterID){
1317  Float_t tempDEta, tempDPhi;
1318  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1319  if(!tempTrack) continue;
1320  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1321  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedTracks.push_back(it->second);
1322  }
1323  }
1324  }
1325 
1326  return tempMatchedTracks;
1327 }
1328 
1329 //________________________________________________________________________
1330 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1331  Int_t TrackPos = -1;
1332  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1333  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1334  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1335  if(currTrack->GetID() == trackID){
1336  TrackPos = iTrack;
1337  break;
1338  }
1339  }
1340  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));
1341  }else TrackPos = trackID; // for ESD just take trackID
1342 
1343  vector<Int_t> tempMatchedClusters;
1344  multimap<Int_t,Int_t>::iterator it;
1345  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1346  if(!tempTrack) return tempMatchedClusters;
1347  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1348  if(it->first == TrackPos){
1349  Float_t tempDEta, tempDPhi;
1350  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1351  if(tempTrack->Charge()>0){
1352  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedClusters.push_back(it->second);
1353  }else if(tempTrack->Charge()<0){
1354  dPhiMin*=-1;
1355  dPhiMax*=-1;
1356  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedClusters.push_back(it->second);
1357  }
1358  }
1359  }
1360  }
1361 
1362  return tempMatchedClusters;
1363 }
1364 
1365 //________________________________________________________________________
1366 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1367  Int_t TrackPos = -1;
1368  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1369  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1370  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1371  if(currTrack->GetID() == trackID){
1372  TrackPos = iTrack;
1373  break;
1374  }
1375  }
1376  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));
1377  }else TrackPos = trackID; // for ESD just take trackID
1378 
1379  vector<Int_t> tempMatchedClusters;
1380  multimap<Int_t,Int_t>::iterator it;
1381  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1382  if(!tempTrack) return tempMatchedClusters;
1383  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1384  if(it->first == TrackPos){
1385  Float_t tempDEta, tempDPhi;
1386  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1387  Bool_t match_dEta = kFALSE;
1388  Bool_t match_dPhi = kFALSE;
1389  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1390  else match_dEta = kFALSE;
1391 
1392  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1393  else match_dPhi = kFALSE;
1394 
1395  if (match_dPhi && match_dEta )tempMatchedClusters.push_back(it->second);
1396  }
1397  }
1398  }
1399 
1400  return tempMatchedClusters;
1401 }
1402 
1403 //________________________________________________________________________
1404 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dR){
1405  Int_t TrackPos = -1;
1406  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1407  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1408  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1409  if(currTrack->GetID() == trackID){
1410  TrackPos = iTrack;
1411  break;
1412  }
1413  }
1414  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));
1415  }else TrackPos = trackID; // for ESD just take trackID
1416 
1417  vector<Int_t> tempMatchedClusters;
1418  multimap<Int_t,Int_t>::iterator it;
1419  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1420  if(!tempTrack) return tempMatchedClusters;
1421  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1422  if(it->first == TrackPos){
1423  Float_t tempDEta, tempDPhi;
1424  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1425  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedClusters.push_back(it->second);
1426  }
1427  }
1428  }
1429 
1430  return tempMatchedClusters;
1431 }
1432 
1433 //________________________________________________________________________
1435  Float_t sumTrackEt = 0.;
1436  vector<Int_t> labelsMatched = GetMatchedTrackIDsForCluster(event, clusterID, dR);
1437  if((Int_t) labelsMatched.size()<1) return sumTrackEt;
1438 
1439  TLorentzVector vecTrack;
1440  for (UInt_t i = 0; i < labelsMatched.size(); i++){
1441  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(labelsMatched.at(i)));
1442  if(!currTrack) continue;
1443  vecTrack.SetPxPyPzE(currTrack->Px(),currTrack->Py(),currTrack->Pz(),currTrack->E());
1444  sumTrackEt += vecTrack.Et();
1445  }
1446 
1447  return sumTrackEt;
1448 }
1449 
1450 //________________________________________________________________________
1452  TAxis *axisafter = histoRebin->GetYaxis();
1453  Int_t bins = axisafter->GetNbins();
1454  Double_t from = axisafter->GetXmin();
1455  Double_t to = axisafter->GetXmax();
1456  Double_t *newbins = new Double_t[bins+1];
1457  newbins[0] = from;
1458  Double_t factor = TMath::Power(to/from, 1./bins);
1459  for(Int_t i=1; i<=bins; ++i) newbins[i] = factor * newbins[i-1];
1460  axisafter->Set(bins, newbins);
1461  delete [] newbins;
1462  return;
1463 }
1464 
1465 //________________________________________________________________________
1467  if(fSecVectorDeltaEtaDeltaPhi.size()>0){
1468  cout << "******************************" << endl;
1469  cout << "******************************" << endl;
1470  cout << "NEW EVENT !" << endl;
1471  cout << "vector etaphi:" << endl;
1472  cout << fSecVectorDeltaEtaDeltaPhi.size() << endl;
1473  cout << "multimap" << endl;
1474  mapT::iterator iter = fSecMap_TrID_ClID_ToIndex.begin();
1475  for (iter = fSecMap_TrID_ClID_ToIndex.begin(); iter != fSecMap_TrID_ClID_ToIndex.end(); ++iter){
1476  Float_t dEta, dPhi = 0;
1477  if(!GetSecTrackClusterMatchingResidual(iter->first.first,iter->first.second,dEta,dPhi)) continue;
1478  cout << " [" << iter->first.first << "/" << iter->first.second << ", " << iter->second << "] - (" << dEta << "/" << dPhi << ")" << endl;
1479  }
1480  cout << "mapTrackToCluster" << endl;
1481  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(fInputEvent);
1482  for (Int_t itr=0;itr<esdev->GetNumberOfTracks();itr++){
1483  AliVTrack *inTrack = esdev->GetTrack(itr);
1484  if(!inTrack) continue;
1485  TString tCharge;
1486  if(inTrack->Charge()>0) tCharge = "+";
1487  else if(inTrack->Charge()<0) tCharge = "-";
1488  cout << itr << " (" << tCharge << ") - " << GetNMatchedClusterIDsForSecTrack(fInputEvent,inTrack->GetID(),5,-5,0.2,-0.4) << "\t\t";
1489  }
1490  cout << endl;
1491  multimap<Int_t,Int_t>::iterator it;
1492  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it) cout << it->first << " => " << it->second << '\n';
1493  cout << "mapClusterToTrack" << endl;
1494  Int_t tempClus = it->second;
1495  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it) cout << it->first << " => " << it->second << '\n';
1496  vector<Int_t> tempTracks = GetMatchedSecTrackIDsForCluster(fInputEvent,tempClus, 5, -5, 0.2, -0.4);
1497  for(UInt_t iJ=0; iJ<tempTracks.size();iJ++){
1498  cout << tempClus << " - " << tempTracks.at(iJ) << endl;
1499  }
1500  }
1501  return;
1502 }
1503 
1504 //________________________________________________________________________
1506  if(fVectorDeltaEtaDeltaPhi.size()>0){
1507  cout << "******************************" << endl;
1508  cout << "******************************" << endl;
1509  cout << "NEW EVENT !" << endl;
1510  cout << "vector etaphi:" << endl;
1511  cout << fVectorDeltaEtaDeltaPhi.size() << endl;
1512  cout << "multimap" << endl;
1513  mapT::iterator iter = fMap_TrID_ClID_ToIndex.begin();
1514  for (iter = fMap_TrID_ClID_ToIndex.begin(); iter != fMap_TrID_ClID_ToIndex.end(); ++iter){
1515  Float_t dEta, dPhi = 0;
1516  if(!GetTrackClusterMatchingResidual(iter->first.first,iter->first.second,dEta,dPhi)) continue;
1517  cout << " [" << iter->first.first << "/" << iter->first.second << ", " << iter->second << "] - (" << dEta << "/" << dPhi << ")" << endl;
1518  }
1519  cout << "mapTrackToCluster" << endl;
1520  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(fInputEvent);
1521  for (Int_t itr=0;itr<esdev->GetNumberOfTracks();itr++){
1522  AliVTrack *inTrack = esdev->GetTrack(itr);
1523  if(!inTrack) continue;
1524  TString tCharge;
1525  if(inTrack->Charge()>0) tCharge = "+";
1526  else if(inTrack->Charge()<0) tCharge = "-";
1527  cout << itr << " (" << tCharge << ") - " << GetNMatchedClusterIDsForTrack(fInputEvent,inTrack->GetID(),5,-5,0.2,-0.4) << "\t\t";
1528  }
1529  cout << endl;
1530  multimap<Int_t,Int_t>::iterator it;
1531  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it) cout << it->first << " => " << it->second << '\n';
1532  cout << "mapClusterToTrack" << endl;
1533  Int_t tempClus = it->second;
1534  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it) cout << it->first << " => " << it->second << '\n';
1535  vector<Int_t> tempTracks = GetMatchedTrackIDsForCluster(fInputEvent,tempClus, 5, -5, 0.2, -0.4);
1536  for(UInt_t iJ=0; iJ<tempTracks.size();iJ++){
1537  cout << tempClus << " - " << tempTracks.at(iJ) << endl;
1538  }
1539  }
1540  return;
1541 }
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)